Jquery / javascript interact between windows?

I have a window with a link.

When a link is clicked, a modal block opens (it loads another page in an iframe).

The iframe contains the login. When a user logs in, I would like the modal field to close and send a message to the original page.

How should I do it?

Is there a javascript event or a way to send a message between a window and its associated iframe?

+4
source share
1 answer

You can call the parent window JavaScript method from an iframe like this.

 window.parent.methodName(); 

If you want to access any item from the parent window.

 $('elementSelector', window.parent).doAnyJQueryOperation(); 

If you want to send a message to the parent window.

 window.parent.alert('Message from iframe'); 
+4
source

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


All Articles