最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Delete first page in JQuery Mobile history - Stack Overflow

matteradmin6PV0评论

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});
Post a comment

comment list (0)

  1. No comments so far