一大早發現,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://blog.csdn.net/wangjj_016/article/details/5304784