如何确认用jquery插入到DOM上的图像是完全加载的

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

本文关键字:DOM 图像 加载 插入 何确认 确认 jquery      更新时间:2023-09-26

我在寻找帮助:

我有一段代码到一个变量,我放置到一个div使用jquery,之后我把该div上的conde我重定向到另一个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"

使用图片加载事件

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

您可以使用img tag 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"' />