How jQuery Mobile handles page changes
To understand this situation you need to understand how jQuery Mobile works. It uses ajax to load other pages.
First page is loaded normally. Its HEAD
and BODY
is loaded into the DOM
, and they are there to await other content. When second page is loaded, only its BODY
content is loaded into the DOM
.
Here's an official documentation: http://jquerymobile.com/demos/1.2.0/docs/pages/page-links.html
Unfortunately you are not going to find this described in their documentation. Ether they think this is a common knowledge or they forgot to describe this like my other topics. (jQuery Mobile documentation is big but lacking many things).
Solutions:
In your second page, and every other page, move your SCRIPT
tag into the BODY
content, like this:
Move all of your javascript into the original first HTML. Collect everything and put it inside a single js file, into a HEAD
. Initialize it after jQuery Mobile has been loaded.
Use rel="external" in your buttons and every elements you are using to change page. Because of it ajax is not going to be used for page loading and your jQuery Mobile app will behave like a normal web application.
More informations
More information with working examples can be found in my blog ARTICLE or even HERE.