H5子iframe向父iframe跨域传值

父页面:
window.onload = function() {
            if(window.addEventListener){
                window.addEventListener("message", handleMessage, false);
            }
           else{                window.attachEvent("onmessage", handleMessage);
            }

            function handleMessage(event) {
                debugger;
                event = event || window.event;
                if (event.origin === 'http://10.180.216.115:3036') {
                    $("#mapContent").val(event.data.address)
                }
            }
        }
  var iWidth=800;                         //弹出窗口的宽度;
  var iHeight=600;                        //弹出窗口的高度;
  var iTop = (window.screen.height-30-iHeight)/2;      //获得窗口的垂直位置;
  var iLeft = (window.screen.width-10-iWidth)/2;        //获得窗口的水平位置;
  window.open("http://10.180.216.115:3037/#/login?address="+ $("#mapContent").val(),'题目', 'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+', top='+iTop+',left='+iLeft+', toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no')

 


子页面:
let data = {}
      data.address = currentAddress.value.address;
      data.lat = currentAddress.value.lat;
      data.lng = currentAddress.value.lng;
      data.city = currentAddress.value.city;
      data.discrict = currentAddress.value.discrict;
      data.township = currentAddress.value.township;
      window.opener.postMessage(data,"*")
        console.log(currentAddress.value)

 

posted @ 2022-04-07 18:46  DreamCatt  阅读(548)  评论(0)    收藏  举报