簡體   English   中英

window.postMessage Internet Explorer 11支持

[英]window.postMessage internet explorer 11 support

我正在嘗試使用postMessage()將數據發送到從父窗口派生的新窗口。 postMessage()在chrome / firefox中工作正常,但使用Internet Explorer時,似乎在我的addEventListener上令人窒息,並且沒有數據發送到新頁面。

我知道對於IE,您應該使用已經實現的attachEvent ,但是子頁面支持addEventListener ,而父頁面在引用子頁面時不支持。

家長:

var newTab = window.open('community_PrinterFriendlyEligibility');
if (newTab.addEventListener) {
     console.log('add1');
     newTab.addEventListener('load', function() {
         console.log('add2');
         newTab.postMessage(data,'*');
     });

 } else if (newTab.attachEvent) {
     console.log('attach1');
     newTab.attachEvent('load', function() {
         console.log('attach2');
         newTab.postMessage(data,'*');
     });
 }

兒童:

if (window.addEventListener) {
    console.log('add');
    window.addEventListener('message', function(event) {
         //process chrome
    }, false);
} else if (window.attachEvent) {
    console.log('attach');
    window.attachEvent('message', function(event) {
         //process IE
     });
 }  

在IE中進行調試:

 Parent Window: attach1 child Window: add 

在Chrome中調試:

 Parent Window: add1 add2 child Window: add 

因此,在IE中,對子窗口的父引用沒有addEventListener但子窗口接受addEventListener

Afaik在IE11中不需要: http ://caniuse.com/#search=addEventListener

剛剛在IE11中對此進行了測試,可以確認它是否使用addEventlistener。

您是否在父頁面中模擬IE8? 這將使用附加。

新窗口將恢復為默認值(Edge),它將使用add。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM