image.onload在IE7中没有触发两次 [英] image.onload not firing twice in IE7

查看:131
本文介绍了image.onload在IE7中没有触发两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

适用于IE6和FireFox;但由于某些原因不在IE7中。

It works in IE6, and FireFox; but for some reason not in IE7.

在Page_Init上使用ASP.NET我填充了一个章节列表,这些章节是指向书中图像的链接以及一个javascript保存pageID的数组。

Using ASP.NET on the Page_Init I populate a list of chapters that are links to the image in the book as well as a javascript array which holds the pageIDs.

ex。

第1章 - > href =javascript:seePage( 4);

Chapter 1 --> href="javascript:seePage(4);"

这是我正在使用的实际代码:

here is the actual code I am using:


var availablePages = ['1002_001','1002_002','1002_003','1002_004','1002_005'];

function seePage(index) {
    $get('imgSingle').src = 'graphics/loading.gif';
    var img = new Image();
    img.src = 'get.jpg.aspx?size=single&id=' + availablePages[index];
    img.onload = function() {
         var single = $get('imgSingle');
         single.src = img.src;
    }
}

当我点击第1章时,图像加载正常全面(IE6,7,FF)并点击第二章链接也有效;然而,在(并且仅在)IE7中点击同一章两次(第1章,第2章,然后是第1章),图像卡在加载图像上...我在这里拉出我的头发... 。

When I click on Chapter 1, the image loads fine across the board (IE6,7,FF) and clicking on a second chapter link also works; however, in (and only in) IE7 does clicking on the same chapter twice (chap1, chap2, then chap1 again) does the image get stuck on the 'loading' image... I'm pulling out my hair here guys...

推荐答案

这是因为IE会缓存图像,并且onload事件在加载之后永远不会触发。

It's caused because IE will cache the image, and the onload event will never fire after it's already been loaded.

您需要在src之前定位onload事件。

You need to position the onload event before the src.

var availablePages = ['1002_001','1002_002','1002_003','1002_004','1002_005'];

function seePage(index) {
    $get('imgSingle').src = 'graphics/loading.gif';
    var img = new Image();
    img.onload = function() {
         var single = $get('imgSingle');
         single.src = img.src;
    }
    img.src = 'get.jpg.aspx?size=single&id=' + availablePages[index];
}

这篇关于image.onload在IE7中没有触发两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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