如何讓iframe框架自適應內容高度
阿新 • • 發佈:2019-01-25
<iframe src="edit-index.html" width="969" id="my_iframe" frameborder="no" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<script language="javascript">
$(function(){var document_height="";
//iframe自適應高度
var timeIframe;
window.onload=function(){
timeIframe=setTimeout(GetIframeStatus,10);
}
function GetIframeStatus()
{
var iframe = document.getElementById("my_iframe");
var iframeWindow=iframe.contentWindow;
if(iframeWindow.document.readyState=="complete")
{
var iframeWidth,iframeHeight;
iframeWidth=iframeWindow.document.documentElement.scrollWidth;
iframeHeight=iframeWindow.document.documentElement.scrollHeight;
iframe.width=iframeWidth;
iframe.height=iframeHeight;
}
else
{
timeIframe=setTimeout(GetIframeStatus,10);
}
}
})
</script>