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>

 

posted @ 2018-10-03 09:24  CorderBob  阅读(4147)  评论(0编辑  收藏  举报