ddouglascarr
ddouglascarr

Reputation: 1442

jquery-mobile: How do I not add a page to the history stack

I have an application which includes a series of forms, each on their own page.

I do not want some of these pages to be added to the history stack. So that when the user presses back, it skips them.

Jquery-mobile does this with dialogs. You can configure this to happen with ALL pages (or any other data-role) but not with just some pages.

Does anyone know how to do this? Alternatively, would it be possible to create a new data-role that extends "page". If that was possible, then I could disable history for all of those pages.

Upvotes: 4

Views: 5097

Answers (3)

gnl
gnl

Reputation: 151

I was facing the same issue and I was going berserk!!! Finally, I was able to do it with the following code that does just that!

The code below automatically prevents storing the changed locations for all pages in the current document.

Please note that it has been tested with jqm 1.4.2

<script>
    $(document).on("pagebeforetransition",function(event, ui){ 
        ui.options.changeHash = false; 
    }) ;
</script>

Hope it helps

Upvotes: 1

Rain Diao
Rain Diao

Reputation: 926

in this case, you can call $.mobile.changePage() by yourself:

$.mobile.changePage( "url", {
changeHash: false //do not track it in history
});

http://jquerymobile.com/demos/1.2.0/docs/pages/page-navmodel.html http://jquerymobile.com/demos/1.2.0/docs/api/methods.html

Upvotes: 5

Alex Hope O&#39;Connor
Alex Hope O&#39;Connor

Reputation: 9694

Checkout this question, pretty much the same as what you are trying to do.

How to modify jQuery mobile history Back Button behavior

Thanks, Alex.

Upvotes: 0

Related Questions