2010-12-22 17 views
4

可能重複:
Javascript: Cancel/Stop Image Requests中止活動圖像請求

如何中止的圖像請求,其仍然在飛?

例子:

var img = new Image(); 
var img.src = "http://www.google.co.in/images/nav_logo29.png"; 
window.setTimeout(function(){ 
    //Code to abort/cancel image request if it hasn't triggered onload or onerror even after 20 seconds of sending request. 
},20000) 
+0

>我想這就是你想要的。 http://stackoverflow.com/questions/2813168/how-to-cancel-a-jquery-load – naveen 2010-12-22 04:38:37

回答

0

一旦瀏覽器發送的,它的完成圖像的要求,則無法「取消」了。

你可以做的大部分是在這種情況下隱藏圖像元素或顯示友好的消息。

1

在Firefox中,將圖像的src設置爲空字符串將會中止任何活動請求。