browserstate / history.js

History.js gracefully supports the HTML5 History/State APIs (pushState, replaceState, onPopState) in all browsers. Including continued support for data, titles, replaceState. Supports jQuery, MooTools and Prototype. For HTML5 browsers this means that you can modify the URL directly, without needing to use hashes anymore. For HTML4 browsers it will revert back to using the old onhashchange functionality.
http://browserstate.github.com/history.js/demo/
Other
10.74k stars 1.35k forks source link

jQuery Mobile error: TypeError: e.originalEvent is undefined #233

Open johnstaveley opened 11 years ago

johnstaveley commented 11 years ago

I am using History.js with jQuery mobile (latest versions of both) and when I change state I get the following javascript error even though everything appears to work fine:

TypeError: e.originalEvent is undefined var poppedState = e.originalEvent.state,

the error occurs in jQuery.mobile-1.2.0.js on this line:

onPopState: function( e ) { var poppedState = e.originalEvent.state, fromHash, toHash, hashChanged;

my calling code:

History.pushState({ view: 'home' }, "Home", "Main?view=home");

it appears the history handling in jquery mobile is colliding with History.js. Is this a problem or can I ignore it? I don't like errors hanging around that I don't understand! Cheers

shaderbytes commented 11 years ago

There is a clash between JQuery mobile and this library because they are both handling the History .. I got rid a similar error "Cannot read property 'state' of undefined" by calling this line of code before pageinit.

$.mobile.pushStateEnabled = false;

I found the info on this page : http://jquerymobile.com/demos/1.2.0/docs/pages/page-navmodel.html

LJNielsenDk commented 9 years ago

You have to set this before document ready, otherwise it won't work.