问题描述
IE9显示错误的完整
属性,其中包含以下内容:
IE9 is showing false complete
property with the following:
$("<img/>",{src:"http://farm2.static.flickr.com/1104/1434841504_edc671e65c.jpg"}).each(function(){console.log(this.complete);});
如果您在浏览器控制台中运行此代码,(允许足够的时间加载图像)再次运行它。 IE9是我测试过的唯一一个第二次显示false的浏览器。这似乎是一个已知的错误,从一些简单的谷歌搜索。
我需要一个解决方法,如果有人有。
If you run this code in a browser console, (allow enough time for the image to load) then run it again. IE9 is the only browser I've tested showing false the second time. This seems to be a known bug, from some simple google searching. I need a workaround if anyone has one.
这可能是一个时间问题,因为让上面的代码设置为全局变量a la:
This could be a timing issue, as letting the code above set a global variable a la:
var img = $("<img....
然后测试该变量的属性会得到不同的结果:
and then testing that variable's properties gives different results:
img[0].complete === true
和
img[0].readyState === "complete"
必须有其他方式来获取此信息。任何想法......谢谢!
There must be some other way of getting this infomation. Any ideas... Thanks!
推荐答案
我用这个:
function doWhenLoaded(obj,callback) {
if($.browser.msie) {
var src=$(obj).attr("src");
$(obj).attr("src","");
$(obj).attr("src",src);
}
$(obj).one("load",callback).each(function(){
// alert(this.readyState+" "+this.src);
if(
this.complete
|| this.readyState == "complete"
|| this.readyState == 4
|| ($.browser.msie && parseInt($.browser.version) == 6)
) {
$(this).trigger("load");
}
});
}
样本:
doWhenLoaded("#main_background_img",function(){
$("#main_background_img").slideDown(1000);
});
这篇关于如何判断IE9中的图像何时已存在于浏览器缓存中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!