简体   繁体   中英

Javascript- history.pushState() not working in IE

I use the History.js to save the current (History can be found here: https://github.com/browserstate/History.js/blob/master/README.md )

Now it works in all browsers except Internet Explorer. I use IE9, I don't know if it works on IE10. Anyway, my URL should look something like this: http://rlb.local/?bereich=3 but in IE it looks like this: http://rlb.local/#http%3A//rlb.local?bereich=3 I have no idea what the reason is that Internet Explorer displays the URL so strangely.

I pass the URL to the pushState-method like this: History.pushState(null, null, "?bereich=3");

EDIT: Here is the function that uses this:

function scrollingFunction(page, speedVar){
    $.scrollTo( {top: 0 , left: getPosition(page)} , speedVar, { axis:'xy', easing: 'easeInOut'});
    $('.mainNav').removeClass("active");
    $('#navLink_'+page).addClass("active");
    History.pushState(null,null,"?bereich="+page);
}

The function is used to scroll between different pages. The variable "page" is the current page number like "1", "2","3", etc. I tried it with the second parameter as a String but this doesn't work either.

Not sure whether this is what you want to know: IE9 simply doesn't support the HTML5 history API. Therefore History.js emulates it using the hash part of the URL.

If however you're wondering why your url is not http://rlb.local/#?bereich=3 - no idea there. This should work automatically as History.js tries to use the shortest possible URL according to its website. Maybe it has something to do with your ".local" domain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM