網頁中的iframe自適應高度寬度,延遲計算高寬度
//在iframe onlad時執行下面的程式碼 id="myFileTableIframe"
function IframeAutoHeightAndWidth(){ var iframe=document.getElementById("myFileTableIframe"); if (iframe) { var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow; if(isNull(id)){ //延遲一秒 setTimeout(function(){ if (iframeWin.document.body) { var height=iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight; var width=iframeWin.document.documentElement.scrollWidth || iframeWin.document.body.scrollWidth; document.getElementById("myFileTableIframe").style.height=height+"px"; document.getElementById("myFileTableIframe").style.width=width+"px"; } },1000); }else{ var height=iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight; var width=iframeWin.document.documentElement.scrollWidth || iframeWin.document.body.scrollWidth; document.getElementById("myFileTableIframe").style.height=height+"px"; document.getElementById("myFileTableIframe").style.width=width+"px"; } } }