Javascript 检查 iFrame 是否已加载。一度。查询

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6980677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 00:06:15  来源:igfitidea点击:

Check if iFrame is loaded. ONE time. Jquery

javascriptjqueryiframeload

提问by Oliver 'Oli' Jensen

I know there is many of possiblites when it comes to check if an iFrame content has been loaded. Although, is there anyway to limit it?

我知道在检查 iFrame 内容是否已加载时有很多可能性。虽然,无论如何要限制它吗?

Example, if I have an iframe, and I need to check if everything has loaded, I can use the load() function. Although, if I click a NEW link inside the iframe, it will run the load() function again.

例如,如果我有一个 iframe,并且需要检查所有内容是否已加载,则可以使用 load() 函数。但是,如果我单击 iframe 内的新链接,它将再次运行 load() 函数。

What I wish to know, is there any way to do, so jquery only checks the FIRST time the iFrame content has been loaded?

我想知道的是,有什么办法可以做,所以 jquery 只检查 iFrame 内容已加载的第一次?

I have tried everything, nothing works.

我已经尝试了一切,没有任何效果。

回答by redsquare

Use jquery .one, it does the unbind work for you.

使用 jquery 。,它为你做解除绑定的工作。

$('#iframe').one('load', function() {


});

Example fiddle.

示例小提琴

回答by supakeen

You can unset the load callback again once it gets called.

一旦它被调用,您可以再次取消设置加载回调。

$('#iframe').load(function() {

  // do things which are awesome

  $('#iframe').unbind('load');

});