HTML5 Cross Browser iframe post message - child to parent?


The parent object provides a reference to the main window from the child.

The following is the parent code. The directive below triggers the iFrame to send a message to the parent window every 3 seconds. No initial message from the main window needed!

var a= window.addEventListener ? "addEventListener" : "attachEvent";// here a is the event method
var b= window[a];// here b is the eventer
var c= a== "attachEvent" ? "onmessage" : "message";// here c is the message event

// Listen to message from child window
b (c,function(e) {
   var d= e.message ? "message" : "data";// here d is the key
   var f= e[d];//here f is data
},false);

Updated on: 24-Jan-2020

115 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements