IE 9的onhashchange [英] onhashchange with IE 9
问题描述
我有以下代码
$(document).ready(function() {
if ("onhashchange" in window) {
alert("The browser supports the hashchange event!");
}
function test(){
alert("hash has changed = " + window.location.hash)
}
window.onhashchange =test;
}
我单击更改哈希值的链接,并且在所有其他浏览器中,我在test
但是在IE中,我收到第一个警报,说它支持onhashchange,但是当哈希更改时,什么也没有发生.
有什么想法吗?
MSDN文档上有一个示例 我在您的示例中将其添加到head标签中,并且效果很好. 此元标记基本上是说要像在IE 8中那样运行页面,而不是在IE 9中(仍处于beta版).
有关此元标记的更多信息,请阅读这里 I have the following code I click a link that changes the hash and in all other browsers I get the alert in However in IE I get the first alert saying it supports onhashchange but then when the hash changes nothing happens. Any ideas? There's an example on the MSDN doc page. Basically, I removed all the extra "map" stuff on their page and the only difference between theirs and your example is that they include the following meta-tag: I added this to the head tag in your example and it worked fine. This meta-tag basically says to run the page as if it were in IE 8 and not IE 9 (which is still in beta). For more information on this meta-tag read here 这篇关于IE 9的onhashchange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!<meta http-equiv="X-UA-Compatible" content="IE=8" >
$(document).ready(function() {
if ("onhashchange" in window) {
alert("The browser supports the hashchange event!");
}
function test(){
alert("hash has changed = " + window.location.hash)
}
window.onhashchange =test;
}
test
<meta http-equiv="X-UA-Compatible" content="IE=8" >