Question: I'm opening a window like this:

```
var w = window.open("", "window-name", opts);

```

Then I create an URL using some dynamic data and set the window to that URL like this:

```
w.location.href = url;

```

My problem is that I need to retrieve the URL I previously set to the window later for editing. Doing this doesn't work:

```
var url = w.location.href;

```

Because that's a security violation in my case and triggers an exception.

I can't just save the URL as a "global" variable since this needs to work across pages. I don't want to use cookies, because the URL **should** be reset when the window closes. Using cookies would add more complexity since it forces me to do cleanup before the window closes, and it adds bug risks. I will use it as a last resort.

Is there any way to retrieve the URL of a window instance after the URL has been set to something on a different domain?

Answer: 
Use the `window.name` property like this...

```
var w = window.open('http://www.example.com', 'www.previousurlhere.com', opts);

```

Then, when new window opens (assuming it's yours), from within the new window you can grab the `window.name` data like...

```
var previousUrl = window.name;

```

And that should do it.
The browser won't tell you the state of previously visited URLs of other domains. That happens for security reasons. 

If you're working on the same domain, perhaps you can query the [History API](https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history) to get what you need. Alternatively, you may store the visited URLs on the client via LocalStorage or another solution.