Unable to get property 'state' of undefined or null reference (JQuery Mobile 1.4.5)
jmfillman opened this issue · comments
I am getting this error in IE 11, when clicking the href link, and when History.pushState is invoked.
Basic HTML:
<script type="text/javascript" src="jquery-1.11.3.min.js"></script> <script src="jquery.history.js"></script> <script type="text/javascript" src="jquery.mobile-1.4.5.min.js"></script> <script> $(window).load(function() { var State = History.getState(), $log = $('#log'); // Log Initial State
History.log('initial:', State.data, State.title, State.url);
console.log('initial:', State.data, State.title, State.url);
// Bind to State Change
History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
// Log the State
var State = History.getState(); // Note: We are using History.getState() instead of event.state
History.log('statechange:', State.data, State.title, State.url);
console.log('statechange:', State.data, State.title, State.url);
});
});
function loadPage(e, event) {
event.preventDefault();
if (e === 1) {
$('.contentDiv').load('pageOne.html');
History.pushState({state:1}, "Page1", "?state=1");
}
else {
$('.contentDiv').load('pageTwo.html');
// History.pushState({state:2}, "Page2", "?state=2");
}
};
</script>
<div class="contentDiv">
<p>Content Goes Here</p>
</div>
Debugger points to the following code in "jquery.mobile-1.4.5.min.js":
return this.preventHashAssignPopState?(this.preventHashAssignPopState=!1,void b.stopImmediatePropagation()):this.ignorePopState?void(this.ignorePopState=!1):!b.originalEvent.state&&1===this.history.stack.length&&this.ignoreInitialHashChange&&(this.ignoreInitialHashChange=!1,location.href===e)?void b.preventDefault():(c=d.parseLocation().hash,!b.originalEvent.state&&c?(f=this.squash(c),this.history.add(f.url,f),void(b.historyState=f)):void this.history.direct({url:(b.originalEvent.state||{}).url||c,present:function(c,d){b.historyState=a.extend({},c),b.historyState.direction=d}}))}
In FireFox 40.0.2, FireBug reports the following:
TypeError: b.originalEvent is undefined
Remove jquery mobile and the error goes away, but I plan to use jquery mobile.