Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

javascript

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!

like image 984
BeachRunnerFred Avatar asked Dec 02 '09 02:12

BeachRunnerFred


People also ask

How do I pass data from popup to parent window?

parent. document. getElementById('panelControlId') worked for me. It provided the handle to the panel holding this child window, thereby allowing to call pnl.

What window object method can be used to open a new browser window?

The open() method opens a new browser window, or a new tab, depending on your browser settings and the parameter values.


2 Answers

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?

like image 98
Doug Neiner Avatar answered Oct 05 '22 00:10

Doug Neiner


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.

like image 20
Moishe Lettvin Avatar answered Oct 05 '22 00:10

Moishe Lettvin