index.html 709 B

123456789101112131415161718192021
  1. <!-- This Source Code Form is subject to the terms of the Mozilla Public
  2. - License, v. 2.0. If a copy of the MPL was not distributed with this
  3. - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
  4. <html>
  5. <body>
  6. <button id=post>post!</button>
  7. </body>
  8. <script>
  9. window.addEventListener("message", event => {
  10. console.log("Document message", event, event.data, event.source !== window && event.source === window.parent);
  11. });
  12. window.addEventListener("click", event => {
  13. if (event.target.id === "post") {
  14. console.log("click!")
  15. window.parent.postMessage("ping!", "*");
  16. }
  17. });
  18. console.log(window.parent === window)
  19. </script>
  20. </html>