Quickest way to pass data to a popup window I created using window.open()?

I have javascript code to open a popup window using the window.open() function. I'd like to pass data from the parent window to that popup window and I can't seem to find an elegant or simple solution anywhere on google or SO, but it seems like there should be support for this built into JS. What's the easiest way to pass data to the popup window?

Thanks in advance for all your help!


Due to security restrictions it is super easy only if the parent window and the popup are from the same domain. If that is the case just use this:

// Store the return of the `open` command in a variable
var newWindow = window.open('http://www.mydomain.com');

// Access it using its variable
newWindow.my_special_setting = "Hello World";

In the child (popup) window, you could access that variable like this:

window.my_special_setting

Was there something specific you wanted to do past that?


Assuming it's the same domain, do what Bart said. If it's a different domain, you can use the hash tag to pass some data, eg http://www.example.com/page#some_data_for_the_page. You could URL encode key/value pairs if you have enough data to warrant that.