开发者

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 w开发者_运维百科ork, but it's inelegant as the first page is shown first.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜