1

I'd like to open an url in a different window from the browser console and access to that window from the former window. This url is different from the one I'm working with and I'm the owener of both.

For example, let's suppose I'm in Mozilla in window 1 in http://localhost:3000, I open a window 2 in http://localhost:8000. If I save the window object in a variable, it appears to be blank:

>>> let newWin = window.open("http://localhost:8000","_blank","width=1000,height=800")
undefined
>>> newWin
Restricted 
>>> newWin.document.URL
"about:blank" 

While I want to get:

>>> newWin.document.URL 
"http://localhost:8000/"

I checked several questions in StackOverflow and this should work, am I doing anything wrong? Is it even posible to perform?

My final purpose is to embed this code in a React component and access to its inner HTML. I'm first trying in the console but I must say that it is not working in the React component either.

chococroqueta
  • 694
  • 1
  • 6
  • 18
  • 1
    Mmm, that makes sense, but even if I own both websites and include the first domain in cors allowed origins? – chococroqueta Jan 23 '23 at 13:52
  • my mistake. i think you are right, it should work – Ali Jan 23 '23 at 21:09
  • I found a question similar to mine: https://stackoverflow.com/q/18625733/11692632, so I think you were right and it's not trivial to window open a different domain, but I though with cors allowed origins it would be different... – chococroqueta Jan 24 '23 at 11:46
  • i searched a lot and i think this is the answer you are looking for https://stackoverflow.com/questions/25098021 . what i learned is that you can open a window with cross origin domain, but you cannot use any javascript inside it. – Ali Jan 26 '23 at 06:16

0 Answers0