2

Possible Duplicate:
Access a window by window name

Suppose I do:

window.open(url, 'somewindowname');

How can I get a reference to the newly opened window using the window name ('somewindowname') using jQuery?

Perhaps something in the form of $('somewindowname') or something....

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
pillarOfLight
  • 8,592
  • 15
  • 60
  • 90
  • You cannot. Check http://stackoverflow.com/questions/7243970/access-a-window-by-window-name – Madhur Aug 06 '12 at 18:22
  • @Madhur Actually, you can, check out my answer and further details in http://stackoverflow.com/questions/4785399/how-to-tell-if-a-window-exists-in-javascript/4785453#4785453 – Ruan Mendes Aug 06 '12 at 18:28

4 Answers4

0

you can set the window as a variable like so

var foo;
foo = window.open(url, 'somewindowname');

you can then

use

foo.close();

to close the window for instance. Note that this is a javascript variable not a jquery variable.

Eonasdan
  • 7,563
  • 8
  • 55
  • 82
0

It has nothing to do with JQuery.

After opening the window for the first time, you can get a reference to it by using window.open function again and assigning the returned value to a variable:

var existingWindow = window.open(url, "somewindowname");

Edit

Here is a JSFiddle demo.

fardjad
  • 20,031
  • 6
  • 53
  • 68
0

Reference elements inside of the pop up window:

var imgsInPopUp = $("img", somewindowname.document.body);
epascarello
  • 204,599
  • 20
  • 195
  • 236
0

There is some undocumented behavior that lets you get a reference to a window by name. I've mentioned it in this answer How to tell if a window exists in Javascript?

// Opened a window without storing a handle, but gave it a name
window.open('/some/url', 'xxx');

// Now I need to get a reference to that window
// Calling open without setting a url gets you
// a reference and doesn't reload the window
var win = window.open('', 'xxx')

Here's an example

Community
  • 1
  • 1
Ruan Mendes
  • 90,375
  • 31
  • 153
  • 217