History.js PushState in html 4 browser (IE) changes the url incorrectly

1.2k Views Asked by At

Im usnig History.js to push a url but in IE it appends the page name.

if my original url is : http://www.mydomain.com/Home.aspx

and then I execute the following:

var url = window.location.protocol + '//' + window.location.host + '/Home.aspx?id=2&pl=4'; History.pushState(null, null, url)

In Chrome my url becomes : http://www.mydomain.com/Home.aspx?id=2&pl=4

In IE 8 my url becomes: http://www.mydomain.com/Home.aspx#Home.aspx?id=2&pl=4

If I paste the IE 8 url in chrom my code fails...

Firstly, what should the correct html 4 url look like and secondly, how do I fix it?

1

There are 1 best solutions below

1
On

I believe you are not pushing a state properly, try reformatting the url you push e.g. History.pushState({data: 'home'}, null, '/Home/').

Or maybe you thought that pushing a state also sends a request to server like you did there with a query? It does not buddy.

Therefore, dont expect anything to work by pasting the state u pushed into other browsers. First, because other browsers have no history about your site and secondly you need to catch the statechange event with History.

e.g.

History.Adapter.bind(window, 'statechange',
       function() {
         if (History.getState().data.page === 'home') {
           //do what u would like with current state
         }
     );