• 完美iframe自适应宽度和高度(支持ie,ff)


    在ie下能实现的功能,对照着FF下的方法与属性修改就行了。今天终于把这个问题彻底解决了,记录一下。
    感谢http://www.cnblogs.com/Cheese_Ren/

    js代码如下:

    代码
    //iframe高度自适应
    function IFrameReSize(iframename) {  
        
    var pTar = document.getElementById(iframename);  
        
    if (pTar) {  //ff
            if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight) {  
                pTar.height 
    = pTar.contentDocument.body.offsetHeight;  
            } 
    //ie
            else if (pTar.Document && pTar.Document.body.scrollHeight) {  
                pTar.height 
    = pTar.Document.body.scrollHeight;  
            }  
       }  

    //iframe宽度自适应
    function IFrameReSizeWidth(iframename) {  
        
    var pTar = document.getElementById(iframename);  
        
    if (pTar) {  //ff
            if (pTar.contentDocument && pTar.contentDocument.body.offsetWidth) {  
                pTar.width 
    = pTar.contentDocument.body.offsetWidth;  
            }  
    //ie
            else if (pTar.Document && pTar.Document.body.scrollWidth) {  
                pTar.width 
    = pTar.Document.body.scrollWidth;  
            }  
       }  

    使用方法如下:

    <iframe src="Main.aspx" scrolling="no" frameborder="0" height="100%" id="mainFrame" width="100%" onload='IFrameReSize("mainFrame");IFrameReSizeWidth("mainFrame");'></iframe>

    参考:
    http://www.cnblogs.com/greatverve/archive/2009/12/17/1626109.html 

  • 相关阅读:
    centos 部署.NET CORE
    nginx 负载均衡
    graylog centos7 部署
    springboot 2.x centos 7.0 部署
    HashMap源代码阅读理解
    服务器安装redis
    java ---- gradle
    uboot-makefile总览
    makeFile
    Spring 推断构造方法
  • 原文地址:https://www.cnblogs.com/greatverve/p/1627027.html
Copyright © 2020-2023  润新知