Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.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 尝试获取iframe内容高度总是失败_Javascript_Html_Iframe - Fatal编程技术网

Javascript 尝试获取iframe内容高度总是失败

Javascript 尝试获取iframe内容高度总是失败,javascript,html,iframe,Javascript,Html,Iframe,我正在尝试使用javascript获取网页中某个iFrame的内容高度 但是obj.contentWindow.document.body.scrollHeight总是给出150px(或者如果我将iframe元素本身的高度设置为默认值) 父HTML页面和iframe内容在我的电脑上都是本地的,并且共享同一个文件夹 有什么建议吗 我的代码的相关部分: ... <iframe id="I2" name="Content" src="home.html" style="width: 860px

我正在尝试使用javascript获取网页中某个iFrame的内容高度

但是obj.contentWindow.document.body.scrollHeight总是给出150px(或者如果我将iframe元素本身的高度设置为默认值)

父HTML页面和iframe内容在我的电脑上都是本地的,并且共享同一个文件夹

有什么建议吗

我的代码的相关部分:

...

<iframe id="I2" name="Content" src="home.html" style="width: 860px; margin-left: 330px; top: 0px; border: none; overflow:hidden" 
     scrolling="no" 
     onload="onloadingContent(this)">
</iframe>

...

<script>
function onloadingContent(obj) 
{
    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
} 

...
。。。
...
函数onloadingContent(obj)
{
obj.style.height=obj.contentWindow.document.body.scrollHeight+'px';
} 
...

yes,发布您的代码并cssedited问题-添加代码yes,发布您的代码并cssedited问题-添加代码