window-opener-targetOrigin.html 1.1 KB

12345678910111213141516171819202122232425
  1. <html>
  2. <body>
  3. <script type="text/javascript" charset="utf-8">
  4. const url = require('url')
  5. if (url.parse(window.location.href, true).query.opened != null) {
  6. // Ensure origins are properly checked by removing a single character from the end
  7. window.opener.postMessage('do not deliver substring origin', window.location.origin.substring(0, window.location.origin.length - 1))
  8. window.opener.postMessage('do not deliver file://', 'file://')
  9. window.opener.postMessage('do not deliver http without port', 'http://127.0.0.1')
  10. window.opener.postMessage('do not deliver atom', 'atom://')
  11. window.opener.postMessage('do not deliver null', 'null')
  12. window.opener.postMessage('do not deliver \\:/', '\\:/')
  13. window.opener.postMessage('do not deliver empty', '')
  14. window.opener.postMessage('deliver', window.location.origin)
  15. } else {
  16. const opened = window.open(`${window.location.href}?opened=true`, '', 'show=no')
  17. window.addEventListener('message', function (event) {
  18. window.opener.postMessage(event.data, '*')
  19. opened.close()
  20. })
  21. }
  22. </script>
  23. </body>
  24. </html>