It has nothing to do with the page being properly loading or the dom not ready, it’s purely that you’re going to a whole new page and incorrectly thinking that you’re able to do things with it still.
Your script is changing the page with window.location
. Immediately after that line, the page changes and your script stops running. There’s nothing else you can do on this page that would affect the other, after you change the window’s location.
solved Simple Javascript DOES not work as intended