zoukankan      html  css  js  c++  java
  • iframe2016/4/12

    js操作iframe 

    contentWindow    
    在服务器环境下测试
    contentDocument
    二种方法的区别
    子级iframe修改父级元素内容
    window.parent
    window.top与window.parent的区别

    window.top:是当前文件最顶端的那个文件,window.parent:是当前文件上面的文件

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    
    <body>
    <div style="200px; height:200px; background:red;"></div>
    </body>
    </html>

    上面是iframe4

    下面是iframe5

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    
    <body>
    <div style="200px; height:400px; background:green;"></div>
    </body>
    </html>
    

      父文件

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script>
    window.onload = function(){
        var aInput = document.getElementsByTagName('input');
        var oIframe = document.getElementById('iframe1');
        
        function changeHeight(){
            
            setTimeout(function(){
                oIframe.height = oIframe.contentWindow.document.body.offsetHeight;
            },100);//防止转向文件与changeHeight函数同时运行
            
        }
        changeHeight();
        
        aInput[0].onclick = function(){
            oIframe.src = 'iframe4.html';
            changeHeight();
        };
        
        aInput[1].onclick = function(){
            oIframe.src = 'iframe5.html';
            changeHeight();
        };
    };
    </script>
    </head>
    
    <body>
    <input type="button" value="切换1" />
    <input type="button" value="切换2" />
    <iframe id="iframe1" src="iframe4.html" scrolling="no"></iframe>
    </body>
    </html>
  • 相关阅读:
    素数
    java线程和线程池的使用
    Android SnackBar:你值得拥有的信息提示控件
    Java读取数据库数据生成柱状图
    hdu 2255奔小康赚大钱 KM算法模板
    Codeforces 446C —— DZY Loves Fibonacci Numbers(线段树)
    设计模式_门面模式
    hdu 1811 Rank of Tetris 并查集+拓扑排序
    使用openstack的虚拟机模版注意事项
    【JAVA】merge two array by order
  • 原文地址:https://www.cnblogs.com/hduhdc/p/5383658.html
Copyright © 2011-2022 走看看