Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在chrome中获取iframe主体html内容_Javascript_Jquery_Html - Fatal编程技术网

Javascript 在chrome中获取iframe主体html内容

Javascript 在chrome中获取iframe主体html内容,javascript,jquery,html,Javascript,Jquery,Html,我在获取iframe的HTML内容时遇到问题 JQuery: $( document ).ready(function() { var template_html = $("#get_template_html").contents().find('body').html(); alert(template_html); }); HTML <iframe id="get_template_html" src="templates/1.htm

我在获取iframe的HTML内容时遇到问题

JQuery:

    $( document ).ready(function() {
        var template_html = $("#get_template_html").contents().find('body').html();
        alert(template_html);
    });
HTML

<iframe id="get_template_html" src="templates/1.html"></iframe>

这在Mozilla Firefox中运行良好,但在Google Chrome中显示空白警报窗口

原因可能是什么


非常感谢

向iframe添加
onload
,并调用JS函数

你的JS:

function afterLoading(){
    var template_html = $("#get_template_html").contents().find('body').html();
    alert(template_html);
}
你的HTML

<iframe id="get_template_html" src="templates/1.html" onload="afterLoading();"></iframe>


听起来好像iframe没有完全加载,请尝试使用而不是文档就绪:
$(window')。on('load',function(){…})
或仅绑定iframe onload事件并设置逻辑,尝试使用
,但没有成功。
延迟
在这种情况下对您没有帮助。我应该尝试检查iframe是否已完全加载吗?是的,您应该使用:
$(函数(){(“#获取模板_html”)。在('load',函数(){alert($(this.contents().find('body').html());})上帝保佑你:)