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

Ilj*_*lja 10 javascript iframe jquery jquery-masonry

正如你在这个页面上看到的那样http://musicglaze.com/chase-status-let-you-go-feat-mali-feed-me-remix/#comments
评论部分是不合适的,经过研究我明白了这是因为负责样式的插件(http://masonry.desandro.com/)被调用

$(document).ready(function(){

});
Run Code Online (Sandbox Code Playgroud)

功能.然而,在此之后内容被加载到iframe中,因此改变其高度,但是当插件考虑其原始高度而没有内容时,一切都搞砸了.有什么我可以使用的行为类似于这个伪代码?

Document ready AND iframe content loaded {

//My jQuery code

}
Run Code Online (Sandbox Code Playgroud)

geo*_*lee 19

$('#iframeId').load(function() { ... });而不是onReady.根本问题是允许父框架访问iframe内容存在跨域安全风险,因此onReady不可用,但onLoad仍可访问.有关详细信息,请参阅:http://www.nczonline.net/blog/2009/09/15/iframes-onload-and-documentdomain/


mon*_*ght 3

相同的ready()函数

$(document).ready(function() {
    $('#frameId').ready(function() {
    ...
    });
})
Run Code Online (Sandbox Code Playgroud)