是否改变图像的src属性停止下载的形象呢? [英] Does changing the src attribute of an image stop the image from downloading?

查看:89
本文介绍了是否改变图像的src属性停止下载的形象呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说,我有两个手风琴标签。第一个负载数百张照片,是开放在页面加载时。

Let's say that I have two accordion tabs. The first one loads hundreds of images and is open when the page loads.

我希望能够停止下载图像,如果用户点击了第二个手风琴选项卡上。将通过改变JS图像的src属性停止下载图像?或者,请求只是继续,直至竣工和在页面上显示不出来?

I want to be able to stop the images from downloading if the user clicks on the second accordion tab. Will changing the src attributes of the images via js stop the images from downloading? Or do the requests just continue until completion and not show up on the page?

推荐答案

我有一个加载SO徽标时我为另一个问题做出准确3秒的脚本。

I have a script that loads the SO logo in exactly 3 seconds that I had made for another question.

http://alexturpin.net/slowimage/slowimage.php

使用它,我试图重现该问题:

Using it, I tried to reproduce the problem:

var img = new Image();
img.onload = function() {
    alert("loaded");
};
img.src ="http://alexturpin.net/slowimage/slowimage.php";

setTimeout(function() {
    img.src = "";
}, 1000);

http://jsfiddle.net/Xeon06/RrUvd/1/

从我收集,在Chrome中,的onload 不被解雇,但浏览器不断呈现出微调,如果我走在网络选项卡上,找到我的形象,并检查它的内容,它的存在。所以,我的答案是,图像仍然加载,至少在Chrome。

From what I gather, in Chrome, the onload doesn't get fired, but the browser keeps on showing a spinner and if I go on the network tab and find my image and check it's content, it's there. So my answer would be no, the image still loads, at least in Chrome.

这是一个有趣的问题,我建议你尝试,并在尽可能多的浏览器尽可能测试它,写一些博客文章就可以了。

This is an interesting problem, I suggest you try and test it in as many browsers as possible and write some kind of blog post on it.

这篇关于是否改变图像的src属性停止下载的形象呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆