2

The question is simple: why doesn't my console show a result based on the code below? There is no message 'Loaded' in the console after this code has been executed... Seems like 'onload' has interaction problems with 'about:blank' window. Maybe 'about:blank' has permanent 'readyState' property which always describes 'complete'?

P.S. Tested it only in Google Chrome.

<!DOCTYPE html>
<head></head>
<body>
    <script>
        let newWindow = window.open('about:blank')

        newWindow.onload = function() {
            console.log('Loaded')
        }
    </script>
</body>
</html>
dedavarera
  • 53
  • 5
  • I don't think you can do that unless the new window/tab is in the same domain that your parent is. – Omar Siddiqui Jul 30 '21 at 14:09
  • Look at the the answer and comments [here](https://stackoverflow.com/questions/42130817/javascript-new-window-with-dynamic-content-and-blank-url-event-listeners-not-ca) – Omar Siddiqui Jul 30 '21 at 14:14
  • What is the URL of the page where you executed that script? – jsejcksn Jul 30 '21 at 14:27
  • I've tried to execute the code on my local PC through MS Visual Code and via jsbin.com – dedavarera Jul 30 '21 at 17:20
  • Does this answer your question? [Why doesn't onload event work on a tab opend with window.open?](https://stackoverflow.com/questions/38657649/why-doesnt-onload-event-work-on-a-tab-opend-with-window-open) – Ouroborus Jul 30 '21 at 17:23
  • No, It doesnt. Unfortunately... – dedavarera Jul 30 '21 at 19:15
  • Copying + pasting the body of your script into Chrome dev tools JS console and running it results in the console message "Loaded", when I run it at a page on Wikipedia or MDN docs. It fails at StackOverflow. It's definitely related to [same-origin policy](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy) and [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP). – jsejcksn Jul 31 '21 at 17:31

0 Answers0