admin管理员组

文章数量:1434125

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?

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?

Share Improve this question edited Apr 9, 2014 at 8:56 pozuelog asked Apr 9, 2014 at 8:38 pozuelogpozuelog 1,31415 silver badges27 bronze badges 2
  • which version are you using? – Omar Commented Apr 9, 2014 at 8:50
  • I'm using jqueryMovile-1.4.2 & cordova 3.4.0. – pozuelog Commented Apr 9, 2014 at 8:55
Add a ment  | 

2 Answers 2

Reset to default 6

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

本文标签: javascriptDelete first page in JQuery Mobile historyStack Overflow