页面中用到iframe不能完全显示的解决方案
生活随笔
收集整理的這篇文章主要介紹了
页面中用到iframe不能完全显示的解决方案
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
頁面中用到iframe不能完全顯示的解決方案
</iframe>
var iframe = document.getElementById("urlIframe"); ?try
{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
/*
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight; var height = Math.max(bHeight, dHeight);
iframe.height = height; */
iframe.height = bHeight;
}
catch (ex) { }
}
如果在頁面中用到了iframe標簽,有時在瀏覽器中并不能完全顯示iframe,導致有些iframe內的內容不能被顯示,如果遇到這種情況,使用以下js可以解決大多數問題。
?
這是iframe標簽:
<iframe marginwidth="0" src=" " marginheight="0" width="100%" name="i" id="urlIframe" frameborder="0" scrolling="no" onload="reinitIframe()" ></iframe>
?
在加載時執行reinitIframe()函數,以下是函數內容:
?
?
代碼 function reinitIframe() {var iframe = document.getElementById("urlIframe"); ?try
{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
/*
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight; var height = Math.max(bHeight, dHeight);
iframe.height = height; */
iframe.height = bHeight;
}
catch (ex) { }
}
?
?
?
?
?
實際中使用變量bHeight可以正好得到完整的高度,如有需要可以使用dHeight,并得到兩者的最大值,但實際應用中使用dHeight,只是記錄每一次得到的最大值,會帶來一些問題。具體應用還是看需求吧。
posted on 2010-10-27 14:51 Johnny_Z 閱讀(...) 評論(...) 編輯 收藏轉載于:https://www.cnblogs.com/Johnny_Z/archive/2010/10/27/1862623.html
總結
以上是生活随笔為你收集整理的页面中用到iframe不能完全显示的解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jQuery编写widget的一些窍门
- 下一篇: ps cs3中显示任何像素不大于50%选