zoukankan      html  css  js  c++  java
  • iframe自动适应高度1

    js:

    function iFrameHeight() { 
    var ifm= document.getElementById("iframepage"); 
    var subWeb = document.frames ? document.frames["iframepage"].document : ifm.contentDocument;
    if(ifm != null && subWeb != null) { 
    ifm.height = subWeb.body.scrollHeight; 

    }

    iframe:

    <iframe id="iframepage" src="study_1.asp" frameborder="0" scrolling="no" style="100%; " onLoad="iFrameHeight()"></iframe>

     

    下面的兼容性比较好:
    /*兼容FF/IE9/IE8/IE7/IE6*/
    function iframeResize(iframe) {
            try {
                //var iframe = document.getElementById("contentFrame"); //("contentFrame");
                var idocumentElement = iframe.contentWindow.document.documentElement;
                if (idocumentElement.scrollHeight > 560) {
                    iframe.height -= 5;
                    iframe.height = idocumentElement.scrollHeight;
                }
                else {
                    iframe.height = 560;
                }
            }
            catch (e) {
                window.status = 'Error: ' + e.number + '; ' + e.description;
            }
        }

    iframe:

    <iframe id="iframepage" src="study_1.asp" frameborder="0" scrolling="no" style="100%; " onLoad="iframeResize(this)"></iframe>

  • 相关阅读:
    第一章 操作系统引论
    程序流程结构
    IE网页cab插件无法安装
    Java面试题整理(题目内容非原创)
    linux下安装字体
    博客园使用Silence主题装饰
    编码问题总结
    JUnit 4.10 新功能简介——RuleChain 和TemporaryFolder的应用
    Usage and Idioms——Rules
    Usage and Idioms——Theories
  • 原文地址:https://www.cnblogs.com/liujie1111/p/3782105.html
Copyright © 2011-2022 走看看