5

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?

  • Your problem is that everything after the # is NOT sent to the server. So mydomain.com/Home.aspx will never get the id and pl that are after the hash. – patrick Oct 31 '13 at 14:55
  • What you get is intended, I am using in our client site and it behaves the same way you have given and it works good. The URL with Hash will also work correctly in Chrome browsers. – Dilip Rajkumar Nov 04 '14 at 05:35

1 Answers1

0

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
         }
     );
  • The statechange event is not the issue. That all works. If I push '/Home/' and then bookmark that page and then reload the page it wouldn't work as asp.net is expecting '.aspx' at the end of home... Im running this on a Sharepoint site. –  Sep 09 '13 at 08:41