In my React application, I am opening a new window on click of a button. This window is being stored in a variable and I have attached functions for onkeydown
and onbeforeunload
events.
I have observed that these functions are being called only when the url of the window is empty.
window.open('', '', '')
For non-empty urls, these events are not being triggered.
window.open('https://wwww.stackoverflow.com', '', '')
Here is a codesandbox demonstrating this:
Has this got anything to do with the url itself? Please specify if I am missing anything here...
ACTUAL USE CASE:
In my frontend application (which runs on port 3000), I am trying to open a new window which opens the backend URL (which runs on port 8000). So, on a button click in http://localhost:3000, a new window will be opened which points to http://localhost:8000/api/something.
So, I added nginx as a reverse proxy and point '/' to 3000 and '/api' to 8000 and access both of these under port 80 as follows:
http {
upstream backend {
server 127.0.0.1:8000;
}
upstream frontend {
server 127.0.0.1:3000;
}
server {
listen 80;
location /api {
proxy_pass http://backend;
}
location / {
proxy_pass http://frontend;
}
}
}
So, now I am able to access the ui application by going to http://localhost and on the button click, the new window will open http://localhost/api/something. Shouldn't this overcome the same origin issue?