HTML5 Cross Browser iframe post message - child to parent?

HTMLJavascriptProgramming Scripts

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);
raja
Published on 21-Mar-2018 09:51:25
Advertisements