Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

postmessage from iframe to parent

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 key = e.message ? "message" : "data";
    var data = e[key];
    //run function//
},false);


//child page -    

parent.postMessage("loadMyOrders","*");  //  `*` on any domain       
 
PREVIOUS NEXT
Tagged: #postmessage #iframe #parent
ADD COMMENT
Topic
Name
3+4 =