diff --git a/js/events/navigate.js b/js/events/navigate.js index dac95be110b..8c1331cf647 100644 --- a/js/events/navigate.js +++ b/js/events/navigate.js @@ -17,8 +17,17 @@ define([ "jquery", "./../jquery.mobile.ns", "./../jquery.mobile.support" ], func originalEventName: undefined, + // If pushstate support is present and push state support is defined to + // be true on the mobile namespace. isPushStateEnabled: function() { - return $.support.pushState && $.mobile && $.mobile.pushStateEnabled; + return $.support.pushState && + $.mobile.pushStateEnabled === true && + this.isHashChangeEnabled(); + }, + + // !! assumes mobile namespace is present + isHashChangeEnabled: function() { + return $.mobile.hashListeningEnabled === true; }, // TODO a lot of duplication between popstate and hashchange @@ -92,7 +101,7 @@ define([ "jquery", "./../jquery.mobile.ns", "./../jquery.mobile.support" ], func if( self.isPushStateEnabled() ) { self.originalEventName = "popstate"; $win.bind( "popstate.navigate", self.popstate ); - } else { + } else if ( self.isHashChangeEnabled() ){ self.originalEventName = "hashchange"; $win.bind( "hashchange.navigate", self.hashchange ); } diff --git a/js/navigation/navigator.js b/js/navigation/navigator.js index 9cd2ade690b..2ce7d406073 100644 --- a/js/navigation/navigator.js +++ b/js/navigation/navigator.js @@ -239,11 +239,12 @@ define(["jquery", // TODO add a check here that `hashchange.navigate` is bound already otherwise it's // broken (exception?) hashchange: function( event ) { - var history = this.history, hash = path.parseLocation().hash; + var history, hash; - // If pushstate is supported the state will be included in the popstate event - // data and appended to the navigate event. Late check here for late settings (eg tests) - if( $.event.special.navigate.isPushStateEnabled() ) { + // If hashchange listening is explicitly disabled or pushstate is supported + // avoid making use of the hashchange handler. + if(!$.event.special.navigate.isHashChangeEnabled() || + $.event.special.navigate.isPushStateEnabled() ) { return; } @@ -255,6 +256,9 @@ define(["jquery", return; } + history = this.history; + hash = path.parseLocation().hash; + // If this is a hashchange caused by the back or forward button // make sure to set the state of our history stack properly this.history.direct({