简体   繁体   English

删除JQuery Mobile历史记录中的第一页

[英]Delete first page in JQuery Mobile history

I'm doing a Cordova App usin jQuery Mobile. 我正在使用jQuery Mobile做Cordova应用程序。 My first page is a 'Loading' page, where I download all needed data for App. 我的第一页是“正在加载”页面,我在这里下载App所需的所有数据。 After that, App goes to menu. 之后,App进入菜单。 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). 我的问题是,据我所知,只有在使用$ .mobile.changePage(changehash = false)加载页面时,才能禁止在历史记录中插入页面。 I'm using jqueryMovile-1.4.2 & cordova 3.4.0. 我正在使用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. 您需要做两件事,从DOM中删除页面div以及导航历史记录。 This can be done by listening to pagecontainershow and read ui.prevPage object, as it holds data of previous page (not current active one). 这可以通过倾听来完成pagecontainershow和阅读ui.prevPage对象,因为它拥有前一页(不是当前的活动之一)的数据。

When pagecontainershow fires, check the type of returned ui.prevPage , it shouldn't be undefined . pagecontainershow触发时,检查返回的ui.prevPage的类型,它不应该是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 . 如果在此阶段defined (表示您已从DOM中的第一页移动到任何其他页面),则从DOM中$.mobile.navigate.history.stack .remove()和从$.mobile.navigate.history.stack

$.mobile.navigate.history.stack.splice(0,1); this will remove first record in urlHistory stack. 这将删除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();
  }
});

Demo 演示

What's your issue with changehash=false? 你有什么问题,changehash = false?

You should just use it when transitionning from the loading page to the menu. 您应该在从加载页面转换到菜单时使用它。

This looks much like what I do in my own app, except in my case history is handled by Backbone. 这看起来很像我在自己的应用程序中所做的,除了我的案例历史由Backbone处理。

$.mobile.changePage($("#menuPage"), {changeHash: false});

And starting with jquery 1.4, you should no more use $.mobile.changePage but instead : 从jquery 1.4开始,你不应该再使用$ .mobile.changePage而是:

$("body").pagecontainer("change",$("#menuPage"), {changeHash: false});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM