简体   繁体   English

Javascript- history.pushState()在IE中不起作用

[英]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 ) 我使用History.js保存当前(历史记录可以在这里找到: https//github.com/browserstate/History.js/blob/master/README.md

Now it works in all browsers except Internet Explorer. 现在它适用于除Internet Explorer之外的所有浏览器。 I use IE9, I don't know if it works on IE10. 我使用IE9,我不知道它是否适用于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. 无论如何,我的URL看起来应该是这样的: http://rlb.local/?bereich = 3但在IE中看起来像这样: http://rlb.local/#http%3A//rlb.local?bereich = 3我不知道Internet Explorer如此奇怪地显示URL的原因是什么。

I pass the URL to the pushState-method like this: History.pushState(null, null, "?bereich=3"); 我将URL传递给pushState方法,如下所示: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. 变量“page”是当前页码,如“1”,“2”,“3”等。我尝试将第二个参数作为字符串,但这也不起作用。

Not sure whether this is what you want to know: IE9 simply doesn't support the HTML5 history API. 不确定这是否是你想知道的:IE9根本不支持HTML5历史API。 Therefore History.js emulates it using the hash part of the URL. 因此,History.js使用URL的哈希部分来模拟它。

If however you're wondering why your url is not http://rlb.local/#?bereich=3 - no idea there. 但是,如果你想知道为什么你的网址不是http://rlb.local/#?bereich = 3 - 不知道那里。 This should work automatically as History.js tries to use the shortest possible URL according to its website. 这应该自动工作,因为History.js尝试根据其网站使用尽可能短的URL。 Maybe it has something to do with your ".local" domain. 也许它与你的“.local”域名有关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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