窗口onmessage /消息事件在IE中不起作用

时间:2017-08-23 06:02:36

标签: javascript internet-explorer events event-handling

我试图在Java脚本的messageEvent的帮助下从外部窗口获取数据。

function damCallBack() {
  var callBackUrl = 'url to be redirected';
  var myWindow = window.open(callBackUrl, "Select Content", "width=750,height=550");
  // Create IE + others compatible event handler
  var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
  var eventer = window[eventMethod];
  var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
  // Listen to message from child window
  eventer(messageEvent, function(e) {
    var dataReceived = JSON.parse(e.data);
    var imageId = dataReceived.data[0].assetid;
    alert(imageId);
    if (dataReceived) {
      myWindow.close();
    } else {
      console.log("Looks we have not received any data. Here was the data " + dataReceived + " ");
    }
  }, false);
}

这在Chrome和Firefox中都运行良好。但未能在IE中工作。有什么理由不在IE上工作吗?

我已经完成了message | onmessage in IE。但没有运气

0 个答案:

没有答案