zoukankan      html  css  js  c++  java
  • iframe向父级传递参数(用postMessage来解决跨域)

    父页面

    <iframe src="http://localhost:8080/index.html" id="vrId"></iframe>

    父页面接收子页面的参数

    mounted(){
      window.addEventListener('message', function(e){
            console.log(e.data)
        })  
    }

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     iframe页面

    created(){
      top.postMessage(需要传递给父页面的参数)  
    }

    注意:如果使用window.postMessage()  可能会出现   Failed to execute 'postMessage' on 'DOMWindow'     报错
    其实 top就是指向iframe最顶层的窗口,建议是用  top.postMessage()即可

  • 相关阅读:
    阅读代码
    openSips
    rc.local 问题
    MyBatis框架使用(一)
    【数据结构杂谈】
    【AGC052A】
    【杜教筛学习笔记】
    CF618F Double Knapsack
    [NOI2016] 循环之美
    【BZOJ 4668 冷战】
  • 原文地址:https://www.cnblogs.com/tlfe/p/14823329.html
Copyright © 2011-2022 走看看