简体   繁体   English

如何确认通过jquery在DOM上插入的图像是否已完全加载

[英]How to confirm that an image inserted on the DOM with jquery is compleate loaded

I looking for a help on this: 我在此方面寻求帮助:

I have a piece of code into a variable that I place into a div using jquery, after I place the conde on that div I redirect the page to another URL, now here is my problem: That code content an image, I need to redirect the page when I am sure that the image is complete loaded into that div, since this is a cross-domain I can not use .load (jquery), Any suggestion how can I do to confirm that the image was complete loaded so I can redirect after that confirmation? 我将一段代码放入使用jquery放入div的变量中,将conde放在该div之后,我将页面重定向到另一个URL,现在这是我的问题:该代码包含图像,我需要重定向当我确定图像已完全加载到该div中时,在页面上,因为这是一个跨域,所以我不能使用.load(jquery),我建议如何做以确保图像已完全加载,因此可以确认后重定向?

<div id="trackBeaconContainer"></div>

var trackBeacon = "<div id='beacon_08d6ab8d99' style='position: absolute; left: 0px; top: 0px; visibility: hidden;'><img src='http://domain.com/openx/www/delivery/lg.php?bannerid=4&amp;campaignid=3&amp;zoneid=2&amp;loc=1&amp;cb=08d6ab8d99' width='0' height='0' alt='' style='width: 0px; height: 0px;' /></div>"

$j("#trackBeaconContainer").html(trackBeacon);

window.location = "http://otherurl.com"

Use the image load event 使用图片加载事件

$j("#trackBeaconContainer")
    .html(trackBeacon)
    .find("img")
        .load( function() {
            window.location.href = "http://example.com";
         });

您可以使用img标签的onload事件

<img src='http://domain.com/openx/www/delivery/lg.php?bannerid=4&amp;campaignid=3&amp;zoneid=2&amp;loc=1&amp;cb=08d6ab8d99' width='0' height='0' alt='' style='width: 0px; height: 0px;' onload='window.location="http://otherurl.com"' />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM