I spent hours trying to debug a jquery mobile page I had created and finally got it to work. I had put the script it in the data-role=”page” class=”page-map4″ div. I was wondering why this was the case, I would rather this not be magic to me. This didn’t matter if I accessed the page directly, only if I had accessed it from another JQuery Mobile page.
$('.page-map4').live("pageshow", function(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
} else {
error('Geolocation not supported');
}
});
Question: Why does the above script have to be in the page data-role div to work correctly when navigated from another JQuery Mobile page?
For page events I simply do this in my jQuery code. This goes in a
<script>tag-set in the<head>element of a page, after any document binding to the$.mobileglobal: