iframe 樣式控制

<iframe src="..." id="iframe"></iframe>
<script> function changeFrameHeight() {   var ifm = document.getElementById("iframe");   var iframeWindow = ifm.contentWindow;   var body = ifm.contentWindow.document.body;   if (iframeWindow.document.readyState == "complete") {     var iframeWidth, iframeHeight;
    body.style.cssText = "word-wrap:break-word;overflow-x:auto; overflow-y:hidden;";
    //獲取Iframe的內容實際寬度
    iframeWidth = iframeWindow.document.documentElement.scrollWidth;
    //獲取Iframe的內容實際高度
    iframeHeight = iframeWindow.document.documentElement.scrollHeight;
    //設置Iframe的寬度
    ifm.width = '500px';
    //設置Iframe的高度
    ifm.height = iframeHeight;
  }
}
 window.onresize = function () {   changeFrameHeight(); } window.onload = function () {   changeFrameHeight(); } </script>
相關文章
相關標籤/搜索