0
Possible Duplicate:
resume webapp from previous position?如何在jQuery Mobile中設置主頁?
我希望用戶在返回時顯示他們訪問的最後一頁。例如:用戶加載我的應用程序(我正在使用PhoneGap),點擊#second_page,關閉應用程序,再次打開應用程序。我不想#home頁面,而是立即向他展示#second_page。
我會使用localStorage來保存網頁:
$(document).on('pagechange', function() {
localStorage.setItem('lastPage',window.location.hash);
});
我嘗試這樣做:
$(document).bind("mobileinit", function(){
var lastPage = localStorage.getItem('lastPage');
if(lastPage) {
$.mobile.changePage(lastPage);
}
});
,但我得到一個「遺漏的類型錯誤:無法調用未定義的方法‘觸發’」錯誤在jquery.mobile-1.2.0.min.js中:2。
另一個想法是做沿着這些路線的東西:
var redirectedToLastPage = false;
$(document).bind("pageinit", function(){
var lastPage = localStorage.getItem('lastPage');
if(lastPage && !redirectedToLastPage) {
$.mobile.changePage(lastPage);
redirectedToLastPage = true;
}
});
,但它似乎不是很優雅。我應該怎麼做?
查看這個問題我的回答:http://stackoverflow.com/問題/ 12816286 /恢復-web應用從 - 以前的位置/ 12820115#12820115 – adamdehaven