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:
- 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.
- 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.
- 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);" onclick="$('current').src='images/001.jpg';">切换图片</a>,IE6下图片不显示。
<a href="javascript:void(0);" onclick="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);" onclick="MyJrjRelation.checkAttention();return false;">关注此人</a>
总结来说<a href="javascript:void(0);" onclick="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’));
});
转载的。。。。记录下来,以后用。