简体   繁体   中英

data issue addEventListener in IE9

I've to pass some data from iframe to parent.

iframe code

window.parent.postMessage({message: 'Test'}, "*");

Parent Code

  window.addEventListener('message', function (e) { alert('Received message 1 : ' + e.data.message); document.getElementById('ExchangeID').value=e.data.message; }, false); 

This works fine in Firefox, Chrome, Safari. When i run this in IE9 , I get an error that e.data.message is undefined .

What is missing here ?

From the Can I Use... page on Cross-document Messaging :

图片

Partial support in IE8-9 refers to only working in frames/iframes (not other tabs/windows). Also in IE 9 and below an object cannot be sent using postMessage .

You can, however, use the alternative syntax:

window.parent.postMessage("test", "*")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM