M
M
Maxima2010-12-12 01:00:29
JavaScript
Maxima, 2010-12-12 01:00:29

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

6 answer(s)
P
Pavel Virsky, 2010-12-12
@Maxima

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.

J
JeanLouis, 2010-12-12
@JeanLouis

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.

N
nikitammf, 2010-12-12
@nikitammf

The picture has an "onabort" event. Maybe try triggering it( img.fireEvent("abort"))?

S
sedictor, 2010-12-12
@sedictor

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);

S
sedictor, 2010-12-12
@sedictor

$('img').execCommand("Stop", false);

maybe so?

S
sedictor, 2010-12-12
@sedictor

And try not to change src, but remove it altogether removeAttr('src')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question