概述
本地同一浏览器访问本地html文件和访问服务器端html文件,本地iframe没有自适应高度,而服务器端的ifrane自适应了高度。
Chrome 版本 41.0.2272.101 (64-bit)
OS:Win8.1
Chrome访问服务器端HTML文件呈现的结果
立即学习“前端免费学习笔记(深入)”;
Chrome访问本地HTML文件呈现的结果
立即学习“前端免费学习笔记(深入)”;
本地访问的HTML文件Iframe没有根据Iframe里面的页面类容自适应高度
在index.html文件中间中添加Iframe页面,页面加载时,加载src指定的文件路径
<iframe id="indexFrame" name="index" width="800" onload='iFrameHeight("indexFrame")' src="Web/Index/indexIframe.html" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
JS脚本自适应调整Iframe高度
</script> <script type="text/javascript" language="javascript"> function iFrameHeight(id) { var ifm = document.getElementById(id); var subWeb = document.frames ? document.frames[id].document : ifm.contentDocument; if (ifm != null && subWeb != null) { ifm.height = subWeb.body.scrollHeight; } } </script>
立即学习“前端免费学习笔记(深入)”;
Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.
在这里,我猜测是访问本地文件是file协议(file:///),HTML代码和JS代码存在跨域问题。小弟对file协议不熟悉,请大家不吝赐教。
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号