history.js icon indicating copy to clipboard operation
history.js copied to clipboard

History.replaceState() Behavior different in chrome and IE8

Open toni-moreno opened this issue 9 years ago • 3 comments

supose we are in this url.

http://myexample.com?param1=val1&param2=val2

and I set:

History.replaceState(null,null,"http://myexample.com?param3=val3");

On chrome:

URL changes to "http://myexample.com?param3=val3"

(as I wish)

On IE8:

URL changes to "http://myexample.com?param1=val1&param2=val2#?param3=val3"

history.js attach the new parameter on the old URL, prepended with "#" instead of substitute completely.

How can I fix that ?

toni-moreno avatar Apr 29 '15 13:04 toni-moreno

You can't, IE8 doesn't support History API.

You can redirect IE8 from http://myexample.com?param1=val1&param2=val2 to http://myexample.com#param1=va1&param2=val2 if you want. So in your example replaceState will change this url http://myexample.com#param1=va1&param2=val2 to http://myexample.com#param3=val3

gkrasulya avatar Apr 29 '15 15:04 gkrasulya

I don't understand what you mean.

Are you saying that I can do what I with if I use "#" instead of "?" as separator for URL and Query String?

toni-moreno avatar Apr 29 '15 15:04 toni-moreno

Of course, it's not the same. History.js fallbacks to hash if browser doesn't support History API.

Browsers dont send hash part of url to server. So in IE8 you need to check hash on page load and send ajax request to server to get actual data.

gkrasulya avatar Apr 29 '15 17:04 gkrasulya