2011-02-25 120 views
0

我该如何做?jquery:在创建iframe DOM对象后绑定LOAD事件

$('#divToInsert').html('<iframe id="outputPage" src="/Folder/webpage.aspx" width="90%" height="600" frameborder="0" scrolling="yes" style="overflow-x: hidden"><p>WARNING: Your browser does not support iframes. Please contact your adminstrator for assistance.</iframe>'); 
$('#outputPage').unbind('load'); 
$('#outputPage').bind('load', function() { 
    alert('done!'); 
}); 

回答

0

错字?

// ---------v---------------there's a "t" that shouldn't be there 
$('#outputPaget').bind('load', 

纠正后适用于我。

确保DOM也被加载。

http://jsfiddle.net/gz2eS/

$(function() { 
    $('#divToInsert').html('<iframe id="outputPage" src="/Folder/webpage.aspx" width="90%" height="600" frameborder="0" scrolling="yes" style="overflow-x: hidden"><p>WARNING: Your browser does not support iframes. Please contact your adminstrator for assistance.</iframe>'); 
    $('#outputPage').unbind('load'); 
    $('#outputPage').bind('load', function() { 
     alert('done!'); 
    }); 
}); 
+0

类型0#2。抱歉。仍然不起作用。 – 2011-02-25 00:55:09

+0

@Martin:DOM是否加载?我在回答中发布了一个jsFiddle示例。你的代码有效。确保'divToInsert' ID也是正确的。 – user113716 2011-02-25 00:58:31

+0

它工作在Mozilla中,而不是在IE 8中。 – 2011-02-25 00:59:38