How to cancel an image from loading

Quick answer

Setting the src attribute of the img tag to an empty string will interrupt the current download, even on Chrome.

###Details
Nowadays most of browsers implemented that out-of-standard mechanism thought in the old answer to programmatically abort the connection. This is not achieved through a protocol request, but with a client-side in-memory operation. Keep in mind that is not a standard behaviour, but most of vendors courtesy. That is, it could not work on every browser.

I’ve prepared a jsfiddle showing this mechanism in action (keep an eye at the network panel of the inspector).


### Old answer (2011)

Your browser asks for that image with a specific HTTP GET request, as specified in HTTP protocol. Once it asks for it, the http server starts the transfer.

So, it is between the browser (as http client) and the http server.

Since http protocol does not take into account the option to abort a transfer, the browser should implement an out-of-standard mechanism to programmatically abort the connection. But since this is not specified in any standard, i think you won’t find any way to do that with javascript or any client side code.

Leave a Comment