zoukankan      html  css  js  c++  java
  • 同一页面的两个Iframe获取数据

    首先页面:

    <td  style=" 50%" valign="top">
        <iframe name="xxx"
            id="xxx" frameborder="0"
            src="xxxxxxx" 
            style="margin: 0 auto;  100%; height: 100%;">
      </
    iframe> </td> <td style=" 50%" valign="top"> <iframe name="treeFrame" id="treeFrame" frameborder="0" src="xxxxxx" style="margin: 0 auto; 100%; height: 100%;">
      </
    iframe> </td>

    此时左侧的IFrame想要获取到右侧的Iframe中的数据:

    var x = window.parent.document.getElementById("treeFrame");  
    var right = (x.contentWindow || x.contentDocument);  
    if(right.document){  
      right = right.document;  
    } 

    window.parent为父窗口。

    注意使用 contentWindow 和 contentDocument 属性。

    此时 right 就可以看做是 右侧Iframe的 document对象了。

    即:通过right对象来 获取右侧iframe的数据。

    如:

    var obj = right.getElementsByTagName("input");  

    首先页面:

     

    [html] view plain copy
     
    1. <td  style=" 50%" valign="top">  
    2.     <iframe name="xxx"  
    3.         id="xxx" frameborder="0"  
    4.         src="xxxxxxx"   
    5.         style="margin: 0 auto;  100%; height: 100%;"></iframe>  
    6. </td>  
    7. <td  style=" 50%" valign="top">  
    8.     <iframe name="treeFrame"  
    9.         id="treeFrame" frameborder="0"  
    10.         src="xxxxxx"   
    11.         style="margin: 0 auto;  100%; height: 100%;"></iframe>  
    12. </td>   

     

     

    此时左侧的IFrame想要获取到右侧的Iframe中的数据:

     

    [html] view plain copy
     
    1. var x = window.parent.document.getElementById("treeFrame");  
    2. var right = (x.contentWindow || x.contentDocument);  
    3.       if(right.document){  
    4.       right = right.document;  
    5.   }z  

     

     

    window.parent为父窗口。

    注意使用 contentWindow 和 contentDocument 属性。

     

    此时 right 就可以看做是 右侧Iframe的 document对象了。

    即:通过right对象来 获取右侧iframe的数据。

    如:

     

    [html] view plain copy
     
    1. var obj = right.getElementsByTagName("input");  
  • 相关阅读:
    pch文件配置出现 Expected unqualified-id 和 Unkown type name 'NSString'
    App Store Connect Operation Error ERROR ITMS-90032: "Invalid Image Path
    Xcode面板的使用
    KVO的使用
    苹果开发者账号注册-您在注册时提供的地址无效或者不完整
    Apple导出p12证书 导出证书为p12 Apple开发
    iOS开发-导出profile文件
    App Store提交审核报错 ERROR ITMS-90087解决办法
    Win10 的操作中心如果不见了
    什么时候调用dealloc
  • 原文地址:https://www.cnblogs.com/henuyuxiang/p/7426829.html
Copyright © 2011-2022 走看看