简体   繁体   中英

Delete first page in JQuery Mobile history

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();
  }
});

Demo

What's your issue with 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.

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

And starting with jquery 1.4, you should no more use $.mobile.changePage but instead :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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