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

  • SEARCH
  • Home
  • 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 5931661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:43:34+00:00 2026-05-22T14:43:34+00:00

I have a mobile site, which consists of a single HTML page (Mobile.html). The

  • 0

I have a mobile site, which consists of a single HTML page (Mobile.html). The content is loaded dynamically into JQM formatted divs of data-role="page". The only static content on the page is the body tag; everything else is built up and torn down as the user interacts with the page, which is building the DOM from web service calls.

This all works very well, with one major exception. Link handling is broken. Once JQM has appended to the url hash, refresh and navigation breaks. I have been testing various solutions to this problem, and none so far really work.

Using both JQM nightly build and 1.0A4.1, I’ve simplified the problem into this test code:

<body id='CswMobile'>
<div id="StaticPage1" data-role="page" >
    <div id="StaticHeader1" data-role="header"><h1>Static Header 1</h1></div>
    <div id="StaticContent1" data-role="content">
        <ul data-role="listview" data-theme="b">
            <li><a href="#StaticPage1">Static Page 1</a></li>
            <li><a href="#StaticPage2">Static Page 2</a></li>
            <li><a href="#DynamicPageA">Dynamic Page A</a></li>
            <li><a href="#DynamicPageB">Dynamic Page B</a></li>
        </ul>
    </div>
</div>
<div id="StaticPage2" data-role="page">
    <div id="StaticHeader2" data-role="header"><h1>Static Header 2</h1></div>
    <div id="StaticContent2" data-role="content">
        <ul data-role="listview" data-theme="b">
            <li><a href="#StaticPage1">Static Page 1</a></li>
            <li><a href="#StaticPage2">Static Page 2</a></li>
            <li><a href="#DynamicPageA">Dynamic Page A</a></li>
            <li><a href="#DynamicPageB">Dynamic Page B</a></li>
        </ul>
    </div>
</div>

<script type="text/javascript">

    $('#StaticPage1').live('tap', function (event) { return onClick(event); });

    function onClick(event)
    {
        var id = $(event.target.outerHTML).attr('href');
        var $page = $(id);
        if ($page.length === 0) $page = makePage(id);
        $page.live('tap', function (event) { return onClick(event); });
        $.mobile.changePage($page, 'slide');
        return false;
    }

    function makePage(id)
    {
        id = id.replace('#', '');
        $('body').append('<div id="' + id + '" ' + 'data-role="page">')
        var $page = $('#' + id);
        $page.append('<div id="Header_' + id + '" ' + 'data-role="header"><h1>Header of ' + id + '</h1>');
        var $header = $('#Header_' + id);
        $page.append('<div id="Content_' + id + '" ' + 'data-role="content">');
        var $content = $('#Content_' + id);
        $page.append('<div id="Footer_' + id + '" ' + 'data-role="footer">');

        var $li1 = $('<li><a href="#StaticPage1">Static Page 1</a></li>');
        var $li2 = $('<li><a href="#StaticPage2">Static Page 2</a></li>');
        var $li3 = $('<li><a href="#DynamicPageA">Dynamic Page A</a></li>');
        var $li4 = $('<li><a href="#DynamicPageB">Dynamic Page B</a></li>');
        var $ul = $('<ul data-role="listview" data-theme="b"></ul>').append($li1).append($li2).append($li3).append($li4);
        $content.append($ul);
        return $page;
    }
</script>

The static content works just as you would expect, but the dynamic content produces unexpected behavior, typically either a 404 error (GET http://localhost/DynamicPageA 404 (Not Found)), or a JQM “Loading…” animation on an invalid URL in the browser address bar (http://localhostDynamicPageA).

First, I cannot get link handling to work at all without calling $.mobile.changePage();. By this time, the new content is already in the DOM–so why can’t JQM handle the link?

Second, changePage() seems to inject its own quirks. Clicking the same dynamic list item twice returns a 404 error. Refreshing the browser on a dynamic link returns 404.

What is the simplest way to solve this problem using JQM’s infrastructure?

Edit:

Adding a data-url attribute to the “page” divs solves part of the issue–link handling now works on click for dynamic content; however, back (using JQM’s auto-generated ‘Back’ button) and refresh are still broken.

  1. The ‘Back’ button generates this URL: http://localhostdynamicpagea/# with this error: “Fiddler: DNS Lookup for localhostdynamicpagea failed. No such host is known”. The browser’s Back works just fine–so I may just roll my own ‘Back’ button to solve this.
  2. Browser Refresh on a Dynamic page still generates an empty screen with this console log error: “GET http://localhost/DynamicPageB 0 ()”. I would expect a page refresh on this url: http://localhost/Mobile.html#DynamicPageB to refresh Mobile.html less the dynamic hash.
  • 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-05-22T14:43:35+00:00Added an answer on May 22, 2026 at 2:43 pm

    While I was eventually able to get my sample code to work as expected, I again ran into problems when trying to implement in my mobile app–as I am generating all of my content based on the results of AJAX calls. This presents a race-condition with JQM, which is asynchronously parsing the DOM: I nearly always redirect to the new “page” before .page() has been called.

    Fortunately, I found this: http://www.a2zdotnet.com/m/#view.htm?id=196

    Implementing per site suggestions now.

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

Sidebar

Related Questions

I am developing a mobile site which has multiple divs. I have validator set
I'm building my first jquery mobile site and have run into a problem. When
I have an ASP.NET MVC4 site with mobile content. When I deploy this on
I am developing a site for mob using jquery mobile. I have a content
Making a mobile friendly site, I have a single field and a submit button.
I have an existing mobile web site on which I would like my users
I have a mobile website, which currently displays a timetable. The non-mobile site however
I am creating a site which will have a desktop and a mobile theme.
I have a site which is optimized for mobile devices. I also have a
I have WebView which loads one mobile site, I need send to user agent

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.