Javascript: Cancel/Stop Image Requests

I had the exact same issue, when users ‘paged’ quickly through (ajax) search results the browser was still trying to download profile images for every page not just the current one. This code worked for me, called on the paging event just before the new search was run:

//cancel image downloads
if(window.stop !== undefined)
{
     window.stop();
}
else if(document.execCommand !== undefined)
{
     document.execCommand("Stop", false);
}

Essentially it’s like clicking the “Stop” button on the browser.

Tested in IE, FireFox, Chrome, Opera and Safari

Leave a Comment