2

I created a new popup window from an existing page using:

window.open("myUrl","myName","width=200,height=200");

Now on that popup window I have a text input and a button, I want to create an onclick method for the button that sends the text inputs value to the page that created the popup without using a form or php, is this possible?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Stuyvenstein
  • 2,340
  • 1
  • 27
  • 33
  • 2
    http://stackoverflow.com/questions/9994120/javascript-pass-selected-value-from-popup-window-to-parent-window-input-box/10407064#10407064 – Ja͢ck May 24 '12 at 06:35

3 Answers3

7

you can use the window.opener keyword

lets say you have a javascript method doSomething(value){....} in your parent class, then from your POPUP you can call the parent function using

window.opener.doSomething("here is my data from child sent to parent");

UPDATED

MaVRoSCy
  • 17,747
  • 15
  • 82
  • 125
2

Assuming both the parent and the new window are on the same domain, you should be able to directly manipulate their JS environment:

var w = window.open("myUrl", "myName", "width=200,height=200");
var e = w.document.getElementById('someId');
// do something with element e

If they are on different domains, you might need to use window.postMessage or other cross-domain messaging techniques, if window.postMessage is not supported by your targeted browsers.

lanzz
  • 42,060
  • 10
  • 89
  • 98
  • Why? He wants to add a handler on an element in the created window, which does something in the parent window. This can be done in either direction. – lanzz May 24 '12 at 06:45
  • But from child to parent the syntax is different - and it is triggered in child – mplungjan May 24 '12 at 07:31
  • Yes, but you can still accomplish it from parent to child. – lanzz May 24 '12 at 19:59
0

Any open window call forms a get request to new window. This is very simple way that you pass the params you want to send using URL itself like,

var myUrl = "http://example.com/test?myName=" + myName;
window.open(myUrl,"windowName","width=200,height=200");

Now on the page you can get myName as a request parameter. Please try this.

Umesh Aawte
  • 4,590
  • 7
  • 41
  • 51