Answer the question
In order to leave comments, you need to log in
Is it possible to stop the loading of a specific Javascript image?
From the realm of fantasy, of course, but suddenly ...
It is clear that you can stop loading the entire page with stop() and then all downloads will also fall off,
but this is not what you need, you need to say stop to a specific picture if it takes too long to load.
Solution found.
Here is its author paaashka
Really helped to bring our script to the ideal.
Spent a lot of time on me but finished it off with pure JS
Answer the question
In order to leave comments, you need to log in
And if for the picture dynamically create an iframe with it, and if the event from the iframe did not come that the picture was loaded, then delete the iframe along with the picture? Now I tried it - when I delete the iframe, the image loading stops.
You can try two options.
The first, obvious, is to do something with the image itself (img), change the src attribute, convert it to another tag. But it probably doesn't work, which is why you're asking.
The second, theoretically possible option. This is to make an ajax request to the desired image and call the abort method of the XMLHttpRequest object at the right time (for example, the jQuery $.ajax function returns a similar object). Thus, assuming that the browser is caching requests, the image may end up in the cache if successful. This needs to be checked.
The picture has an "onabort" event. Maybe try triggering it( img.fireEvent("abort"))?
The loadedImg function removes the loaded img from the array of not yet loaded ones.
After half a minute, all unloaded images change src, thereby stopping the download
var notLoadedImgs = $('img');
$('img').load(function() {loadedImg(this);}); // loadedImg excludes img from notLoadedImgs
setTimeout(function() {
$(notLoadedImgs).attr('src', '404');
}, 30000);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question