<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Cross Document Messaging</title>
  <style>
    section {
      width: 400px;
      padding: 20px;
      margin-bottom: 10px;
      border: 1px solid #999999;
    }
  </style>
  <script>
    function initiate() {
      const button = document.getElementById("open");
      button.addEventListener("click", openPopup);
      window.addEventListener("message", receiver);
    }
    function openPopup() {
      window.open("popup.html", "popup", "width=400,height=200");
    }
    function receiver(event) {
      const databox = document.getElementById("databox");
      databox.innerHTML = "Message from: " + event.origin + "<br>";
      databox.innerHTML += "message: " + event.data;
    }
    window.addEventListener("DOMContentLoaded", initiate);
  </script>
</head>
<body>
  <section>
    <button type="button" id="open">Open Popup</button>
  </section>
  <section id="databox"></section>
</body>
</html>