Javascript-history.pushState()在IE中不起作用 [英] Javascript- history.pushState() not working in IE

查看:456
本文介绍了Javascript-history.pushState()在IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用History.js保存当前文件(历史记录可在此处找到:

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

现在,它适用于Internet Explorer以外的所有浏览器.我使用的是IE9,但我不知道它是否可以在IE10上运行. 无论如何,我的网址应如下所示: http://rlb.local/?bereich = 3 但在IE中看起来像这样: http://rlb.local/#http%3A//rlb.local?bereich = 3 我不知道Internet Explorer如此奇怪地显示URL的原因是什么.

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.

我将URL传递给pushState方法,如下所示: History.pushState(null,null,?bereich = 3");

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

这是使用此功能的函数:

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);
}

该功能用于在不同页面之间滚动.变量"page"是当前页码,例如"1","2","3"等.我尝试使用第二个参数作为String进行尝试,但这也不起作用.

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.

推荐答案

不确定这是否是您想知道的:IE9根本不支持HTML5历史记录API.因此,History.js使用URL的哈希部分对其进行仿真.

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.

但是,如果您想知道为什么您的网址不是 http://rlb.local/#?bereich = 3 -在那里不知道.当History.js尝试根据其网站尝试使用尽可能短的URL时,这应该会自动工作.也许与您的".local"域有关.

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.

这篇关于Javascript-history.pushState()在IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆