- 时间:2022-04-05 03:40 编辑: 来源: 阅读:
- 扫一扫,手机访问
摘要:window.location.href IE下跳转失效的解决方法
[url=javascript:void(0)]$("a").click(function(){
window.location.href = "xxx.html";
})
代码如上,在IE下,特别是在IE6中,点击超链接之后,浏览器并没有发生跳转行为。
原因可能是因为在href中的javascript:void(0)阻止的事件行为,解决方法如下:
1.在onclick事件中加return false来阻止冒泡:
$("a").click(function(){
window.location.href = "xxx.html";
reutrn false;
})
2.延迟100毫秒
$("a").click(function(){
setTimeout(function(){
window.location.href = "xxx.html";
},100);
})