删除JQuery Mobile历史记录中的第一页 [英] Delete first page in JQuery Mobile history
问题描述
我在使用jQuery Mobile的Cordova应用程序。我的第一页是一个载入页面,我在那里下载所有需要的数据。之后,应用程序进入菜单。我想从历史记录中删除该加载页面。
我的问题是,据我所知,禁止在历史记录中插入页面只能在加载页面时使用$ .mobile.changePage(changehash = false)。
我使用jqueryMovile-1.4.2& cordova 3.4.0。
有人知道这个问题的方法吗?
您需要做两件事,从DOM和导航历史记录中删除页面div。这可以通过监听 pagecontainershow
并读取 ui.prevPage
对象来完成,因为它保存上一页的数据 pagecontainershow
启动时,请检查返回的 ui的类型。 prevPage
,它不应该是 undefined
。如果定义
(表示您已经从DOM的第一页移动到任何其他页面),在此阶段, .remove()
来自DOM和 $。mobile.navigate.history.stack
。
$。mobile.navigate.history.stack.splice(0,1);
这将删除urlHistory堆栈中的第一条记录。
$(document).on(pagecontainershow,function(e,ui){
if(typeof ui.prevPage [0]!==undefined&& ui .prevPage [0] .id ==pageID){
$ .mobile.navigate.history.stack.splice(0,1);
$(ui.prevPage).remove();
}
});
I'm doing a Cordova App usin jQuery Mobile. My first page is a 'Loading' page, where I download all needed data for App. After that, App goes to menu. I want to delete that loading page from history.
My problem is that as far as I know, disable insertion of pages inside history can be done only when pages are loaded using $.mobile.changePage (changehash=false). I'm using jqueryMovile-1.4.2 & cordova 3.4.0.
Does anybody know a approach to this problem?
You need to do two things, remove page div from DOM as well as from navigation history. This can be done by listening to pagecontainershow
and read ui.prevPage
object, as it holds data of previous page (not current active one).
When pagecontainershow
fires, check the type of returned ui.prevPage
, it shouldn't be undefined
. If it is defined
(means you have moved from first page in DOM to any other page) at this stage, .remove()
from DOM and from $.mobile.navigate.history.stack
.
$.mobile.navigate.history.stack.splice(0,1);
this will remove first record in urlHistory stack.
$(document).on("pagecontainershow", function (e, ui) {
if (typeof ui.prevPage[0] !== "undefined" && ui.prevPage[0].id == "pageID") {
$.mobile.navigate.history.stack.splice(0,1);
$(ui.prevPage).remove();
}
});
这篇关于删除JQuery Mobile历史记录中的第一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!