From the course: Web Security: Same-Origin Policies

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Work with a received message

Work with a received message - JavaScript Tutorial

From the course: Web Security: Same-Origin Policies

Start my 1-month free trial

Work with a received message

- [Instructor] So far in our app, we have communication from the opened window to the original window, but sometimes we'll want to do it the other way as well. If something changes in the main page, the page that was opened might need to integrate that. Now window.open is not an asynchronous event. So if we just put code after that, it won't help because the message will be dispatched before the page has finished loading so the message won't be caught. But we have an event handler set up already that has the opened window message the original window when it's done loading. So we can use that as an indication that it's safe to message the opened window. So thinking about this from the perspective of the original window, the receive message function will be called when the message comes in. And if the content of the message is ready, we can go ahead and have the original page message back. So when we received a message,…

Contents