
正文
iframe交互(一)父页面自动高度
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
//父页面源码
<body style="border:1px solid red;width:200px;height:500px;" onload="IFrameResize()">
<script>
function IFrameResize() {
//alert(this.document.body.scrollHeight); //弹出当前页面的高度
var obj = parent.document.getElementById("childFrame"); //取得父页面IFrame对象
//alert(obj.height); //弹出父页面中IFrame中设置的高度
obj.height = this.document.body.scrollHeight; //调整父页面中IFrame的高度为此页面的高度
} </script>
<script type="text/javascript" src="./auto-height.js"></script>
</body>
//子页面源码
<body>
<IFRAME border= marginWidth= frameSpacing= marginHeight= src="iframe.html" frameBorder= noResize scrolling="no" width=%
height=% vspale="" id="childFrame"></IFRAME>
<!-- <iframe id="iframe" name="asd" src="iframe.html" onload="loadIframe(this)" height="" frameborder="" style="border:1px solid blue">
</iframe> -->
<script type="text/javascript">
function loadIframe(doc) {
console.log(doc.contentWindow.document);
}
</script>
</body>
注意:调试时注意是否是本地启动,还是基于代理服务器。本地启动会触发作用于问题导致错误






