zoukankan      html  css  js  c++  java
  • iframe子页面和父页面传值通信

    iframe子页面和父页面传值通信

    1. 相互获取dom元素
    • 在父页面获取子页面的dom元素:
      document.getElementById('iframe_id).contentWindow.document.getElementById('domId');
    //先获取iframe的Id,再在iframe所在的document找dom元素,根据id查找;
    
    • 子页面获取父页面的dom元素
     window.parent.document.getElementById('mask_id');  //window.parent可以回到父页面
    
    1. 相互调用方法
    • 父页面调用子页面方法:iframeName.window.childMethod();

    • 子页面调用父页面方法:parent.window.parentMethod();

    1. 相互调用变量
    • 子页面访问父页面变量:parent.父页面变量;

    • 父页面访问子页面变量: document.getElementById('iframe_id).子页面变量;

  • 相关阅读:
    LeetCode OJ
    LeetCode OJ
    LeetCode OJ
    LeetCode OJ
    LeetCode OJ
    LeetCode OJ
    LeetCode OJ
    LeetCode OJ
    LeetCode OJ
    LeetCode OJ
  • 原文地址:https://www.cnblogs.com/fly-book/p/14903191.html
Copyright © 2011-2022 走看看