I am creating a mobile site using jQuery Mobile, and one of my testers pointed out a problem while reloading, deep linking or bookmarking any pages loaded in the DOM using the standard page loading functions built into jQuery Mobile. I was looking through documentation, forum posts, lists of github errors, etc., etc., Looking for a solution, and I am on my way that I can do wrong. I made a very simple two-page example that shows what I see.
Firstly, I have an index.html page in the root folder of my site (i.e. /index.html ) that looks like this:
<!DOCTYPE html> <html> <head> <title>Home Page</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" /> <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.js"></script> </head> <body> <div data-role="page" data-theme="b" id="main"> <div data-role="header" data-theme="b"> <h1>Home Page</h1> </div> <div data-role="content"> <ul data-role="listview" data-inset="true"> <li><a href="news/">News</a></li> </ul> </div> </div> </body> </html>
I have a second page in the "news" folder (ie /news/index.html ) that looks like this:
<div data-role="page" data-theme="b" data-add-back-btn="true" id="news"> <div data-role="header" data-theme="b"> <h1>News</h1> </div> <div data-role="content"> TODO: page content goes here </div> </div>
So this works great. The home page loads fine. The browser address field displays http://m.example.com/ .
I can click the News link to load this page in the DOM. The browser address field now displays http://m.example.com/news/ . That is where my problem is. If you click the reload button of the browser, the /news/index.html page will reload, but the main context of the main page is completely missing, so there is no jQuery, css or proper HTML document structure. I expect this to be the case considering the URL and contents of its document. But I need links to subpages to work when they are deeply connected to my mobile site.
If you link to a subpage using http://m.example.com/#news/ , this works, if the subpage is loaded correctly, the browser address field will automatically be rewritten to http://m.example.com/news/ . The problem is that people need to know that they need to manually edit the URL whenever they bookmark, tweet, email, etc. URL of the page.
Is there a way to automatically drop the browser to the home page and then start loading the subpage transparent to the user so that the DOM is recreated? What am I missing?