javascript - How to postmessage HTMLIFrameElement? -
i'm having issue passing htmliframeelement
object parent site iframe (located on different domain) using postmessage
method.
this code tried:
var frame = document.getelementbyid('myhtmliframeelement'); frame = json.parse(json.stringify(frame)); event.source.postmessage(frame, "*");
unfortunately, json.parse
/json.stringify
not seem right way of handling htmliframeelement
object. can please advise how pass through htmliframeelement
object correctly?
parsing dom elements json not useful far know. since postmessage()
part of window object, try using window object of frame, found under contentwindow
property of iframe.
so try like:
var frame = document.getelementbyid('myhtmliframeelement'); frame.contentwindow.postmessage( "stuffyouwanttosendtotheiframe", '*' );
and in script inside iframe:
window.addeventlistener('message', function( event ) { // handle message });
Comments
Post a Comment