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!
parent. document. getElementById('panelControlId') worked for me. It provided the handle to the panel holding this child window, thereby allowing to call pnl.
The open() method opens a new browser window, or a new tab, depending on your browser settings and the parameter values.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With