zoukankan      html  css  js  c++  java
  • 多层iframe访问

    注意:

    一、等iframe里面的文件加载完才可以访问;

    二、contentDocument ie6/7不支持;所以采用了contentWindow.document。如果不兼容这两个可以用

      document.getElementById("myframe").contentDocument.getElementById("bframe").contentDocument.getElementById('test').innerHTML;

    三、top.frames["myframe"].frames["bframe"].document.getElementById('test').innerHTML这种方式最短了,看起来很爽的样子。

    四、访问iframe的window和document在chrome里有安全限制的,上传到服务器上测试;

    a.html

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
         <script>
                function t(){
                    alert(document.getElementById("myframe").contentWindow.document.getElementById("bframe").contentWindow.document.getElementById('test').innerHTML);
                    //alert(top.frames["myframe"].frames["bframe"].document.getElementById('test').innerHTML);
                }
        </script>
    </head>
    
    <body>
        <input name="" value="tttt" onClick="t()" type="button">
        <div id="get" style="height:30px;600px;border:1px solid #69F"></div>
        <iframe id="myframe" name="myframe" src="b.html" width="600" height="500"></iframe>
    </body>
    </html>

    b.html

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head>
    
    <body>
        <iframe id="bframe" name="bframe" src="c.html" width="600" height="500"></iframe>
    </body>
    </html>

    c.html

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head>
    
    <body>
    <div id="test">1233333</div>
    </body>
    </html>
  • 相关阅读:
    常见排序算法导读(8)[堆排序]
    常见排序算法导读(7)[希尔排序]
    常见排序算法导读(6)[快排序]
    常见排序算法导读(5)[冒泡排序]
    常见排序算法导读(4)[直接插入排序]
    UI基础
    iOS8之后CoreLocation定位的使用
    关于什么时候用pop什么时候用dismiss
    控制台输出文字改中文
    Quartz2D使用
  • 原文地址:https://www.cnblogs.com/pigtail/p/2619878.html
Copyright © 2011-2022 走看看