文档准备好并加载 iframe 内容后执行 jQuery
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16253714/
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
Execute jQuery once document is ready AND iframe content is loaded
提问by Ilja
As you can see on this page 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://musicglaze.com/chase-status-let-you-go-feat-mali-feed-me-remix/#comments
评论部分是不合适的,经过研究我明白这是因为负责样式的插件(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. Is there something I can use which would behave similar to this pseudocode?
功能。然而,内容在此之后被加载到 iframe 中,因此改变了它的高度,但是由于插件考虑了它的原始高度而没有内容,一切都变得一团糟。有什么我可以使用的东西与这个伪代码的行为相似吗?
Document ready AND iframe content loaded {
//My jQuery code
}
采纳答案by monkeyinsight
same ready() function
相同的 ready() 函数
$(document).ready(function() {
$('#frameId').ready(function() {
...
});
})
回答by geofflee
Use $('#iframeId').load(function() { ... });
instead of 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. For more details, see: http://www.nczonline.net/blog/2009/09/15/iframes-onload-and-documentdomain/
使用$('#iframeId').load(function() { ... });
代替onReady
。潜在的问题是允许父框架访问 iframe 的内容存在跨域安全风险,因此onReady
不可用,但onLoad
仍可访问。更多详情,请参见:http: //www.nczonline.net/blog/2009/09/15/iframes-onload-and-documentdomain/