Panda
Panda

Reputation: 2510

Trying to access the Passed URL from window.open()

I am trying to access the URL of the parsed URL from window.open. I know that may sound stupid, but I'd like to get the value of the URL after user performs a few actions.

Here is the code snippet that I have been playing around with,

function myFunction() {
  var myWindow = window.open("http://google.com", "MsgWindow", "width=200,height=100");

  document.getElementById("demo").innerHTML =
    "The full URL of this page is:<br>" + myWindow.location.href;
}
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

Upvotes: 1

Views: 66

Answers (1)

user149341
user149341

Reputation:

I'd like to get the value of the URL after user performs a few actions.

You can't. The window you've created is a cross-domain frame, so you cannot access its location.

This is necessary because the window's location may contain private information -- for instance, many older web applications will contain session IDs in the URL.

Upvotes: 5

Related Questions