Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9211803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:22:49+00:00 2026-06-18T01:22:49+00:00

Some background; By default when you click a link to a separate HTML page

  • 0

Some background;

By default when you click a link to a separate HTML page JQM loads the first data-role=”page” on that page and attaches it to the DOM of the first page, the thing is JQM only loads that page div and not any scripts etc. that are outside that container.

I have a jQuery mobile app with 5 pages “login.html” “menu.html” “account.html” “settings.html” ..etc

I change pages with like;

 $.mobile.changepage("account.html")

Also I put all my page load logic to my first page login.html like this;

<script>
     $(document).on('pageinit', '#loginpage', function() {
       //do some stuff run some ajax scripts and add some html to its body
    });

  $(document).on('pageinit', '#accountpage', function() {
        //do some stuff run some ajax scripts and add some html to its body
    });

   $(document).on('pageinit', '#settingspage', function() {
        //do some stuff run some ajax scripts and add some html to its body
    });

</script>

While this app works well, Problem is I find it very fragile and hard to survive from unexpected errors. for example;

Since how every page’s body html will load is defined in login.html, this means if any moment user manually refreshs any of these pages, the page will load without running those scripts and load an empty page a without a body. In that moment since the correct DOM is deleted from memory, user is stuck in an app with full of empty pages, only way is he is smart enough to go and type “login.html” to address bar and only then all process can start smoothly.

I think we cant %100 hide address bar, it is visible again after scroll down.

SO this is one problem I come up with, some other weird things can happen and if somehow the DOM gets corrupted only way to use app again is typing login.html address bar, which users probably will not thing about it.

How can I make this app more robust like detecting any DOM corruption or refresh and forward the user to login.html, so he does not stuck in an app with empty pages.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:22:51+00:00Added an answer on June 18, 2026 at 1:22 am

    One way to alleviate some pain is to put your page-specific scripts inside data-role="page" element in the appropriate html files and keep scripts that are the same for every page outside that element (at the and of the body and/or head).

    That way even if the user refreshes the page all necessary scripts will still be executed.
    One problem though, before binding any handlers you need to unbind them first. Otherwise you’ll end up having multiple handlers attached.

    To illustrate this:

    in login.html (updated):

    <div data-role="page" id="loginpage">
        <script>
            $(document).off('pageinit', '#loginpage').on('pageinit', '#loginpage', function() {
                $(document).off('click', '#btnaccount').on('click', '#btnaccount', function(){
                    $.mobile.changePage("jqmaccount.html", {reloadPage: true});
                });
                console.log("paginit in loginpage");
            });
            $(document).off('pageshow', '#loginpage').on('pageshow', '#loginpage', function() {
                console.log("pageshow in loginpage");
            });
        </script>
        <div data-role="content">
            <a id="btnaccount" href="#" data-role="button">Account</a>
        </div>
    </div>
    

    in account.html (updated):

    <div data-role="page" id="accountpage">
        <script>
        $(document).off('pageinit', '#accountpage').on('pageinit', '#accountpage', function() {
            $(document).off('click', '#btnlogout').on('click', '#btnlogout', function(){
                $.mobile.changePage("jqmlogin.html", {reloadPage: true});
            });
            console.log("pageinit in accountpage");
        });
        $(document).off('pageshow', '#accountpage').on('pageshow', '#accountpage', function() {
            console.log("pageshow in accountpage");
        });
        </script>
        <div data-role="content">
            <a id="btnlogout" href="#" data-role="button">Logout</a>
        </div>
    </div>
    

    In this setup if the user refreshes account.html the Logout button on that page will still work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some Background to begin: I've implemented a custom MembershipProvider that validates a user from
I have this little code here when click a link on webview that is
I have a button that on click event I get some information from the
Background: It seems that some text editors and IDEs are starting to get more
For some background info, .NET 4.0 no longer catches CSEs by default: http://msdn.microsoft.com/en-us/magazine/dd419661.aspx I'm
I have some clickable views and I want to set the default available background
Some background info: I am currently writing a bootloader in protected mode while learning
Some background info: I'm trying to run a server program in python 2.5.1 (the
Some background: an 'image' is part of one 'photoshoot', and may be a part
Some background I'm currently building a predominantly classic web app (rather than a single

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.