ajax IE历史推送状态
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11705241/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IE history push state
提问by arik
I have a webpage where the user has the possibility to display the terms and conditions without reloading the page, via AJAX. That, in itself, is no problem, however, I am also trying to push a history state.
我有一个网页,用户可以在其中通过 AJAX 显示条款和条件而无需重新加载页面。这本身没有问题,但是,我也在努力推动历史状态。
That works fine in most browsers, except in IE. For some inexplicable reason, there, the content is loaded via AJAX, but also, a new tab is opened with the previous page. How can I fix this?
这在大多数浏览器中都可以正常工作,但在 IE 中除外。出于某种莫名其妙的原因,在那里,内容通过 AJAX 加载,而且还打开了一个带有上一页的新选项卡。我怎样才能解决这个问题?
You can see the example on this webpage ( http://galaxy-battle.de), try clicking on "T&Cs" in the "Join"-box.
您可以在此网页 ( http://galaxy-battle.de)上查看示例,请尝试单击“加入”框中的“条款与条件”。
回答by Sergei Grebnov
IE9 and below doesn't support pushState. You have an exception when calling the following line
IE9 及以下不支持 pushState。调用以下行时出现异常
window.history.pushState(null, null, pathFullPage);
window.history.pushState(null, null, pathFullPage);
SCRIPT438: Object doesn't support property or method 'pushState' ?terms_and_conditions, line 62 character 21
SCRIPT438:对象不支持属性或方法“pushState”?terms_and_conditions,第 62 行字符 21
You may probably be interesting looking on some workarounds discussed at Emulate/polyfill history.pushstate() in IE
您可能会对在 IE 中的 Emulate/polyfill history.pushstate() 中讨论的一些解决方法感兴趣
回答by kik
Old but still current question. I just want to say I would recommend notto try to emulate pushState on IE.
旧但仍然是当前的问题。我只想说我建议不要尝试在 IE 上模拟 pushState。
Instead of that, you can use a feature detection :
取而代之的是,您可以使用特征检测:
if
history.pushStateis not null (browser supports pushState), you use it and load your content with nifty javascriptif
history.pushStateis null (browser does not support pushState), you change url / follow the link and make a full page change
如果
history.pushState不为空(浏览器支持 pushState),则使用它并使用漂亮的 javascript 加载您的内容如果
history.pushState为空(浏览器不支持 pushState),则更改 url / 按照链接进行整页更改
Of course, this means IE<=9 users won't have all the cool animations other users have. But the question I want to ask is : do you want to see on the net links to your website containing #?
当然,这意味着 IE<=9 用户不会拥有其他用户拥有的所有酷动画。但我想问的问题是:你想在网上看到你的网站包含的链接#吗?
Users may think your app is useful and paste links to it on the web. That's cool, because it brings you some google juice. Now, if that user uses IE and you use history.js, user will paste a link containing a hash.
用户可能认为您的应用程序很有用并在网络上粘贴指向它的链接。这很酷,因为它给你带来了一些谷歌果汁。现在,如果该用户使用 IE 而您使用 history.js,则用户将粘贴一个包含哈希值的链接。
This will defeats proper indexation of public pages of your app, and also will look ugly. My personal opinion is that having a js animation or lightbox for IE users doesn't worth those trade off.
这将破坏您应用程序公共页面的正确索引,并且看起来也很丑陋。我个人的观点是,为 IE 用户提供 js 动画或灯箱不值得进行这些权衡。

