FAQ Database Discussion Community


Why is event.state on window.onpopstate empty when pushing with same location.href (or empty)

javascript,html5-history
When pushing to history and setting data without changing URL: window.history.pushState({ stateName: "myStateName", randomData: window.Math.random() }, "myStateName", location.href); .... and then listen to the pop event and trigger it by pressing the Back button in the browser: window.onpopstate = function(event) { console.log(event.state); //logs null } You will most of the...

History pushed state is not in standalone location.hash or location.href but is in Location object itself

javascript,html5,pushstate,html5-history
Can anyone explain this behavior? I push history state using history.pushState(null, null, '#test');. Then when trying to get state URL in the listener function (didn't find a better way how to listen to pushState changes) using console.log(window.location.hash), it returns empty string, #test hash. console.log(window.location.href) returns whole URL without hash #test...

Can't figure out History JS

javascript,jquery,history.js,html5-history
I am trying to implement a navigation to my ajax controlled site, and I am encountering some strange errors. I am using History JS, the HTML5 only version. This is how I initialize it: function initializeHistory() { var History = window.History; if ( !History.enabled ) { console.log("Not enabled!"); return false;...

code in willTransition callback executed after model callback after a window.alert

firefox,ember.js,alert,back-button,html5-history
I recently encountered a bug with Ember.js. Basically when I click the browser back button in Firefox, Ember.js executes the code in wrong order. The code in willTransition callback right after the line alert("..."); is executed after model callback, which should normally be executed right after alert("..."); is returned. The...

Angular $locationProvider html5Mode / error

javascript,angularjs,routing,html5-history,base-tag
So I'm running into a problem with Angular 1.3.15 and the $locationProvider. Every time I turn html5mode on I get a TypeError: Cannot read property 'replace' of undefined error. If I leave html5mode off, everything works fine. My directory structure is like so (4.DEV being a versioned directory name): public...

HTML5 history API: cannot go backwards more than once

javascript,html,html5,html5-history
I have been trying to get my script working but apparently there is something wrong with it: when I try to go backwards with the browser back button, it stops at the first page backwards i.e. the second time I click the back button, does not work properly and instead...

pushState Executing When Not Supposed To

javascript,html,back-button,html5-history
I am using the HTML history API to manipulate the browser history stack to control navigation using JavaScript on my site. The function I have set up to change pages is working fine, but weirdly, when I added pushState to each individual page change, the pushState fires automatically, so that...

How to avoid calling history.pushState in the popstate event handler?

javascript,jquery,primefaces,html5-history
Let's say we have a <p:commandLink action="…" onclick="history.pushState(…)"> that makes important changes to the state of the page. Primefaces 5.1 generates this HTML: <a id="link1" href="#" onclick="history.pushState( {currentStateKeyWord: 'state1'},'','state1'); PrimeFacesGeneratedFunction(stuff);">Click me for state 1</a> <a id="link2" href="#" onclick="history.pushState( {currentStateKeyWord: 'state2'},'','state2'); PrimeFacesGeneratedFunction(stuff);">Click me for state 2</a> In the popstate event...