I am creating a JQM site with multiple pages, using hashtag. e.g. index.html#a On one of the page I need to initialize a map, say index.html#map. But it occurred to me that no matter where I place the map initialization script, the script would still be executed when the index.html first load, which I want to avoid.
Although I may associate the map script with some buttons, I also want to be able to load the map when someone load index.html#map directly.
So it comes down to how can I associate JavaScript to a subpage (page with hashtag)?
I hope all of that pages are part of a single HTML file. If I am correct you don’t need to use this syntax:
this one will be enough:
Lets say this is your HTML:
Then to associate a javascript to a certain page use this syntax:
Here’s a working jsFiddle EXAMPLE.
Also take a look at my personal blog ARTICLE, it will help you to deal with jQuery Mobile page events. Or take a look at my other ANSWER.