Stefan Kendall
Stefan Kendall

Reputation: 67832

jQuery mobile - persisting the last page the user was on?

I'm trying to bring the user back to the page they closed the application on (<div id="#blah" data-role="page">), but I can't seem to find a way to do this elegantly within the library.

How do I do this?

I tried storing the page id to localStorage and calling $.mobile.changePage at the end of $(document).ready, but that throws odd exceptions. Only using a timeout with changePage seems to work, but it's inelegant as the first page is shown first.

Upvotes: 2

Views: 331

Answers (1)

crv
crv

Reputation: 3024

It sounds like you are having a timing issue here. Why not just change the page once it has been created? You haven't provided all the details about how your pages are being rendered. Like whether they are coming from an HTML document, or being dynamically created using JavaScript before JQM has JQMModfied the page or dynamically after JQM has JQMModified the page.

$('#IdFromStorage').live('createpage', function(){
    $.mobile.changePage('#IdFromStorage');
});

You can find more information about the createpage event here: http://jquerymobile.com/demos/1.0b2/#/demos/1.0b2/docs/pages/page-scripting.html

Upvotes: 1

Related Questions