zoukankan      html  css  js  c++  java
  • 使Iframe的宽高自适应,并且兼容IE 和NC浏览器

    使用Iframe时,高和宽是直接定制好的。很难自适应引用的页面。这时就要用别的方法来进行了。以下整理了2种方法。以做备用:

    1,适应内容自动扩展,在parent页面上加处理script:

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    <script language=JavaScript>
    function autoResize(){
       try{
        document.all["content"].style.height=content.document.body.scrollHeight;
    document.all["content"].style.width=content.document.body.scrollWidth;
       }
       catch(e){}
    }
    </script>

    <style type="text/css">
    <!--
    body {
    margin-left: 100px;
    margin-top: 100px;
    margin-right: 100px;
    margin-bottom: 100px;
    background-color: #CCCCCC;
    }
    -->
    </style></head>

    <body>
    <iframe name="content" style="aho:expression(autoResize())"   width="100%" frameborder=0 src="1.htm" scrolling=no></iframe>
    </body>
    </html>

    2.在引用的文件上加script

    function changeIframeHeight() //自动改变 Iframe 的高度
    {
    if(top != self)
        window.parent.document.getElementById(self.name).height = document.body.scrollHeight;
    }

    function window.onload()
    {
        changeIframeHeight(); //改变 Iframe 高度
    }


    把上面那个放到需要自适应的页面中,用javascript套用就可以了


    第2种方法很好。而且速度够快,第1种方法虽然也能达到效果,不过速度可真是太慢了。

  • 相关阅读:
    Linux网络基础配置
    UVA 116 Unidirectional TSP(dp + 数塔问题)
    修改Hosts文件
    倒排索引
    可以把阿里云上面的一些介绍和视频都看看
    练练脑,继续过Hard题目
    explicit的用法
    auto_ptr的使用和注意
    我写的快排程序
    快速排序、查第k大
  • 原文地址:https://www.cnblogs.com/88223100/p/1238245.html
Copyright © 2011-2022 走看看