A browser lab demonstrating window.postMessage() communication between a parent page and an iframe. Designed to demonstrate cross-window communication using JavaScript in a clean and visual way
https://yassineblue.github.io/postmessage-lab/
- Send messages from the parent page to the child iframe
- Automatic acknowledgment responses from the child iframe
- Manual replies from child iframe to parent page
- Secure cross-origin communication using
event.originandwindow.location.origin - Real-time message logging
- Built using native browser APIs (no external frameworks)
The parent page sends messages to the iframe using window.postMessage().
The iframe listens for messages using window.addEventListener("message"), validates the origin, and replies back using the same API.
All messages are validated using event.origin and window.location.origin to ensure safe cross-origin communication.
index.html→ Parent pagechild.html→ Child iframe window
This project can be run locally using a server such as XAMPP, or directly through the GitHub Pages live demo above.
- Install and open XAMPP
- Start the Apache server
- Move the project folder into:
xampp/htdocs/postmessage-lab/- Open in your browser:
http://127.0.0.1/postmessage-lab/