javascript - Catching the response of the iFrame once receiving the response -
i posting message iframe. iframe returns response boolean. need catch response when response arrives parent window iframe. code not working. idea onthis?
iframe
<iframe id="opiframe" src="https://localhost:9443/oauth2/session" > </iframe>
i'm sending message iframe periodically
var iframe = document.getelementbyid("opiframe"); setinterval(function(){ message ='test' ; console.log('request rp: ' + message); iframe.contentwindow.postmessage(message,"https://localhost:9443/oauth2/session"); },6000);
what need receive response of iframe periodically. code working. added eventlistener iframe below.
iframe.addeventlistener("message",test,false); function test(event){ alert("test"); }
but not firing periodically
it simple: added listener on iframe (as element of parent window's dom), instead of on iframe's window. fix , works:
iframe.contentwindow.addeventlistener("message",test,false);
Comments
Post a Comment