简体   繁体   English

文档准备就绪并加载iframe内容后执行jQuery

[英]Execute jQuery once document is ready AND iframe content is loaded

As you can see on this page http://musicglaze.com/chase-status-let-you-go-feat-mali-feed-me-remix/#comments 正如您在此页面上看到的那样http://musicglaze.com/chase-status-let-you-go-feat-mali-feed-me-remix/#comments
comment section is way out of place, After research I understood that it is caused because plugin responsible for styling ( http://masonry.desandro.com/ ) is called within 评论部分是不合适的,经过研究我明白这是因为负责造型的插件( http://masonry.desandro.com/ )被调用

$(document).ready(function(){

});

function. 功能。 however, content is loaded into iframe after that, therefore changing its height, but as plugin takes into account its original height without content everything gets messed up. 然而,在此之后内容被加载到iframe中,因此改变其高度,但是当插件考虑其原始高度而没有内容时,一切都搞砸了。 Is there something I can use which would behave similar to this pseudocode? 有什么我可以使用的行为类似于这个伪代码?

Document ready AND iframe content loaded {

//My jQuery code

}

Use $('#iframeId').load(function() { ... }); 使用$('#iframeId').load(function() { ... }); instead of onReady . 而不是onReady The underlying issue is that there are cross-domain security risks to allowing the parent frame access to an iframe's content, so onReady is not available, but onLoad is still accessible. 根本问题是允许父框架访问iframe内容存在跨域安全风险,因此onReady不可用,但onLoad仍然可访问。 For more details, see: http://www.nczonline.net/blog/2009/09/15/iframes-onload-and-documentdomain/ 有关详细信息,请参阅: http//www.nczonline.net/blog/2009/09/15/iframes-onload-and-documentdomain/

same ready() function 相同的ready()函数

$(document).ready(function() {
    $('#frameId').ready(function() {
    ...
    });
})

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

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