简体   繁体   English

Jquery / javascript检查div是否完成加载?

[英]Jquery/javascript check if the div finished loading?

I have a facebook like button on my website like that: 我的网站上有一个像facebook一样的按钮:

<div class="fb-like" data-href="https://www.facebook.com/xxx"
             data-send="false" data-width="300" 
             data-show-faces="true">
</div>

I want to use jQuery or java script to check if this div is 100% finished loading on the page and then do other stuff. 我想使用jQuery或java脚本来检查这个div是否在页面上100%完成加载,然后执行其他操作。

I used $(document).ready and .load to check but non of them worked (they do the function even before the div finished loading). 我使用$(document).ready.load来检查但是没有工作(他们甚至在div完成加载之前就完成了这个功能)。 Does this problem have to do anything with the fact that this div contain an iframe from another website ? 这个div是否包含来自另一个网站的iframe这个问题? what am I doing wrong here ? 我在这做错了什么?

UPDATE I just tried this and it did not work at all: 更新我刚试了这个,它根本不起作用:

$(document).ready(function() {
    $(".fb-like").load(function (){
         alert("Loaded :)");
    });
});

I believe the issue is that you need to test if the iframe is loaded rather than the div. 我认为问题是你需要测试iframe是否加载而不是div。 I would suggest changing your selector to include the child iframe and checking for the load event on this. 我建议更改你的选择器以包含子iframe并检查加载事件。

$('.fb-like iframe').load(function() {
  console.log('iframe loaded');
});
$('.fb-like iframe').on(function() {
  console.log('iframe loaded');
 });

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

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