'window.open to read the url of popup

<!DOCTYPE html>
<html>
<body>

<h1>The Window Object</h1>
<h2>The open() and close() Methods</h2>

<button onclick="openWin()">Open "myWindow"</button>
<button onclick="closeWin()">Close "myWindow"</button>

<script>
let myWindow;

function openWin() {
  myWindow = window.open("https://google.com", "", "width=2600,height=500");
  gg = myWindow.location.origin
  alert(gg)
}

function closeWin() {
  myWindow.close();
}
</script>

</body>
</html>

im aware that because of security reasons browsers wont let you read other tabs

but there is something i wanna know if the parent can open the popup page and close the popup page that means the popup page is still can be accessed through parent page

but is there any slightest chance where the parent page can read url of the popup page

using javascript or any library ? if so how ? considering there is no content security headers present for that popup page

iframe is getting blocked because x-frame headers

all i wanted is to just grab the url



Solution 1:[1]

You could access it with myWindow.location.href but only if both windows are on the same subdomain.

Otherwise it is impossible due to same origin policies. Your best option would be to store the url in a variable

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mmm107