admin管理员组文章数量:1302380
I am experiencing some issues binding to the hashchange event in Internet Explorer 7. All other versions of Internet Explorer - ie. 8 & 9 work without issue.
My code is:
$(window).bind('hashchange', function (e) { alert('hash changed'); });
When the hash of the url changes in Firefox, IE8, IE9 I get the alert box, but in IE7, nothing happens.
Anyone experience this before?
I am experiencing some issues binding to the hashchange event in Internet Explorer 7. All other versions of Internet Explorer - ie. 8 & 9 work without issue.
My code is:
$(window).bind('hashchange', function (e) { alert('hash changed'); });
When the hash of the url changes in Firefox, IE8, IE9 I get the alert box, but in IE7, nothing happens.
Anyone experience this before?
Share Improve this question asked Jul 26, 2011 at 16:50 amateuramateur 44.7k71 gold badges196 silver badges324 bronze badges 1- 7 Internet Explorer is not a valid browser... – genesis Commented Jul 26, 2011 at 16:52
2 Answers
Reset to default 8Pretty sure IE6 and IE7 don't support it natively. Did you try using Ben Alman's jquery BBQ script which fixes this?
[Copying this answer from jQuery - hashchange event ]
I just ran into the same problem (lack of hashchange event in IE7). A workaround that suited for my purposes was to bind the click event of the hash-changing links.
<a class='hash-changer' href='#foo'>Foo</a>
<script type='text/javascript'>
if (("onhashchange" in window) && !($.browser.msie)) {
//modern browsers
$(window).bind('hashchange', function() {
var hash = window.location.hash.replace(/^#/,'');
//do whatever you need with the hash
});
} else {
//IE and browsers that don't support hashchange
$('a.hash-changer').bind('click', function() {
var hash = $(this).attr('href').replace(/^#/,'');
//do whatever you need with the hash
});
}
</script>
本文标签: javascriptbinding hashchange event in IE7 issueStack Overflow
版权声明:本文标题:javascript - binding hashchange event in IE7 issue - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741672674a2391696.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论