Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

various page events do not fire on first load. #508

Closed
mrubinsk opened this Issue · 6 comments

2 participants

@mrubinsk

When loading a file for the first time, the various page events do not fire. Example, the following structure:

 <div data-role="page" id="pageOne">
     <div data-role="header"><h3>Page One</h3></div>
     <div data-role="content" class="ui-body"><a href="#pageTwo">Page One</a></div>
 </div>
 <div data-role="page" id="pageTwo">
     <div data-role="header"><h3>Page Two</h3></div>
     <div data-role="content" class="ui-body">Page Two</div>
 </div>

and the following javascript:

<script type="text/javascript">
 $(function() {
   $('#pageOne').live('pageshow', function() { alert('showing pageone'); });
   $('#pageTwo').live('pageshow', function() { alert('showing pagetwo'); });
   alert($.mobile.currentPage);
 });
</script>

Neither of the pageshow events will fire (neither pageOne on first load, or pageTwo, if the url includes the #pageTwo hash). The $.mobile.currentPage alert fires, but shows undefined. Navigating after the page is loaded works as expected.

@scottjehl

Did you place your script between jquery and jquery mobile? These events must be bound before jQuery mobile executes. I just tested on my end and it seems to be working as expected...

@mrubinsk

Nope. The script is placed after both jquery and jquery mobile in the head. It also occurs if I place the script at the end of the body as well.

I put my test script up at:
http://theupstairsroom.com/jq/index.html

Expected behavior:
pagebeforecreate, beforepageshow, pageshow events should fire during initial page load, and beforepageshow, pageshow events should fire at appropriate times during subsequent navigation.

Demonstrated behavior:
No events at all are fired during initial page load, and only the pageshow events are fired during subsequent navigation. The page initialization events are never fired.

@mrubinsk

Oh, wait, all of these have to be bound before jquery mobile is loaded?

@mrubinsk

Ok, I guess that makes sense now that I think about it. Still, how about updating the documentation to make this more obvious?

Thanks for the help.

@scottjehl

The third paragraph on this page explains it, but please send us a pull request if you figure out a better way: http://jquerymobile.com/test/#docs/api/globalconfig.html

Thanks!

@mrubinsk

Done:

#628

Thanks!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.