1.在被嵌入页面获取iframe的src
<iframe id="workSummaryIframe" src="" height="650px" width="99%" scrolling="yes" class="cust" frameborder="0"> //写在被嵌入页面 window.parent.document.querySelector(".cust").contentWindow.location.href;
2.iframe嵌入页面会出现两个滚动条,解决这个问题可以设置iframe高度和内部页面高度保持一致
let abc = document.getElementById('workSummaryIframe'); //页面加载时重新获取并设置高度设置 abc.onload = function () { let height = document.body.offsetHeight-140; abc.style.height = height + 'px'; } //页面大小发生变化是重新设置 window.onresize = function(){ let height = document.body.offsetHeight-140; abc.style.height = height + 'px'; }