IE 9的onhashchange [英] onhashchange with IE 9

查看:91
本文介绍了IE 9的onhashchange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码

$(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文档上有一个示例

<meta http-equiv="X-UA-Compatible" content="IE=8" >

我在您的示例中将其添加到head标签中,并且效果很好.

此元标记基本上是说要像在IE 8中那样运行页面,而不是在IE 9中(仍处于beta版).

有关此元标记的更多信息,请阅读这里

I have the following code

$(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;
}

I click a link that changes the hash and in all other browsers I get the alert in test

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:

<meta http-equiv="X-UA-Compatible" content="IE=8" >

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屋!

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