How to use postmessage in iframe to redirect user to page in main document

I have a page with an iframe on it, and I need a button inside the frame to redirect to another page, if I do it in the usual way, when the contents of the iframe are reloaded, I need the main window to change its URL.

I havent posted any code below as I don't know if this is even possible

+4
source share
1 answer

Yes it is possible. You must send a message from iFrame when the parent receives the message, then you do something. Here is an example: http://jsbin.com/necuvi/2/ . Here are some documents on how this works. https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

+2
source

Source: https://habr.com/ru/post/1584585/


All Articles