jQuery的iframe的load()的事件? [英] jQuery iframe load() event?
本文介绍了jQuery的iframe的load()的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道,如果有这样的事?
Does anyone know if there is such a thing?
我有一个正在被插入 $一个IFRAME阿贾克斯()
和我想要做一些东西后,从iframe中的内容完全加载:
I have a iframe that's being inserted with $.ajax()
and I want to do some stuff after the contents from the iframe are completely loaded:
....
success: function(html){ // <-- html is the IFRAME (#theiframe)
$(this).html(html); // $(this) is the container element
$(this).show();
$('#theiframe').load(function(){
alert('loaded!');
}
....
它的工作原理,但我看到的IFRAME被加载两次(警报也显示了两次)。
it works, but I see the IFRAME is loaded twice (the alert also shows twice).
推荐答案
如果可能的话,你会更好处理负载的iframe的文档中
事件呼唤到包含文档中的功能。这具有在所有的浏览器工作,只运行一次的优点。
If possible, you'd be better off handling the load
event within the iframe's document and calling out to a function in the containing document. This has the advantage of working in all browsers and only running once.
在主文档:
function iframeLoaded() {
alert("Iframe loaded!");
}
在iframe的文档:
In the iframe document:
window.onload = function() {
parent.iframeLoaded();
}
这篇关于jQuery的iframe的load()的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文