jquery/jquery-mobile — Issue #3002: Unable to prevent default on back button
Author: lewismcarey
Created: 2011-11-09 14:46:00+00:00
State: open

I have a page with four subpages. I hoped to prevent the default history behaviour on these pages so that the back button remained relevant to the original history item for the main page.

In an attempt to manipulate the urlHistory stack I tried the following:

$('.subpage').live('pagebeforeload', function() {

$.mobile.urlHistory.stack = $.mobile.urlHistory.stack.slice(0, $.mobile.urlHistory.activeIndex-1);
$.mobile.urlHistory.activeIndex = $.mobile.urlHistory.activeIndex-1;

}

as well as:

$('.subpage').live('pagebeforeload', function() {

var prev = $.mobile.urlHistory.getPrev();
$.mobile.urlHistory.addNew( prev['url'], prev['transition'], prev['title'], prev['pageUrl'], prev['role'] );
$.mobile.urlHistory.activeIndex = $.mobile.urlHistory.stack.length-1;

}

These didn't work. Is it possible to disable the default behaviour of history on certain pages?