IE6下链接ONCLICK事件处理中的请求被ABORTED

IE6下链接ONCLICK事件处理中的请求被ABORTED

一大早发现,ie6下点发起对话没法弹出窗口,ff浏览器就是可以的。开启HttpWatch检测,发现点击的被aborted。

查找资料显示aborted的原因如下。

The (Aborted) value is more complex in its origin. It occurs when IE has started to process the request for a URL (e.g. to download an image), but then decides to cancel the operation. Here are some examples of when this can occur:

  1. If you click on a link or bookmark while a page is downloading, or click on IE’s Stop button, you will see that IE cancels any requests which are still active and HttpWatch shows the (Aborted) result.
  2. A CSS rollover image on a page will start a request when the mouse pointer is moved into its active area. If the mouse pointer quickly moves away again, IE may abort the request if it has not already completed.
  3. Sometimes javascript is used to fire off requests for background tasks or to gather statistics on a page. Often this can lead to aborted results if the javascript does not wait for the response to be received from the server.

继续寻找根源,搜索到发现这个问题是ie6中一个底层 机制的bug,之后的版本已经解决了。据说<a href="javascript:void(0)">或者<a href=#">这样使用a标签的话并不能阻止a标签最后触发一个什么行为,导致ie6会错误的认为页面刷新或者重定向了,并且中断了当前所有连 接,这样新的加载就被aborted了。解决方案最简单的方法有两个,一个是这样使用a标签<a href="xxx(); return false;">,另外一个就是用div替换a标签来用。至此,问题总算解决。

在开发中常使用<a>标签代替button,好处在于可以利用a:hover样式做mouseover效果,但下面的代码在IE6下就有问题,onclick中的请求被aborted。
<a href="javascript:void(0);" οnclick="$('current').src='images/001.jpg';">切换图片</a>,IE6下图片不显示。
<a href="javascript:void(0);" οnclick="MyJrjRelation.checkAttention();">关注此人</a>,IE6下请求失败。

解决方法:
1. 不使用onclick,但必须保证处理函数不返回值,否则浏览器将清空页面,只显示函数的结果。如果checkAttention返回false,浏览器中就会显示false。
<a href="javascript:MyJrjRelation.checkAttention();">关注此人</a>

<a href="javascript:void(MyJrjRelation.checkAttention());">关注此人</a> void返回undefined;

2. 在onclick上加return false阻止浏览器执行href。href属性还是必须的,否则链接就样式失效了。
<a href="javascript:void(0);" οnclick="MyJrjRelation.checkAttention();return false;">关注此人</a>

总结来说<a href="javascript:void(0);" οnclick="MyJrjRelation.checkAttention();return false;">的兼容性最好。

相关知识链接:

http://www.cnblogs.com/zhyt1985/archive/2009/05/27/1490755.html

http://weizuqing1986-126-com.javaeye.com/blog/458141

http://blog.csdn.net/wangjj_016/archive/2010/02/10/5304784.aspx

还有解决办法

比如

$(’#changesite-panel a.city’).click(function(ev){
ev.preventDefault();
changeSite($(this).attr(’rel’));
});

转载的。。。。记录下来,以后用。

<script type="text/javascript"></script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值