0

I want to choose a specific window, and perform operations on that window- I will pass that window as a parameter to another function which does the work...

I know beforehand, that the title of the windows is (for example) "XYZ"

How do I select the window in browser with that title?

I found that in javascript there are ways to assign a title to a window, but I couldnt find a way to search for and find the window which has a specific title.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Arvind
  • 6,404
  • 20
  • 94
  • 143

1 Answers1

4

You cannot select other windows, unless you've already got a reference to it.

There are two methods to get a reference:

  • The window.opener property holds a reference to the window which opened the current one.
  • Saving the return value of window.open() also offers a reference.

Each reference to another window will be a window object. window.document.title can be used to read the value of the title. (where window is the reference to the other window).

Cross-domain restrictions will prevent other windows from being read, though.

See this answer to read the document/window object of embedded frames.

Community
  • 1
  • 1
Rob W
  • 341,306
  • 83
  • 791
  • 678
  • I plan to use this application with Same Origin Policy disabled - the problem is that the js code is loaded into a background page... So I need some way to get a reference to the window (for which I have the title with me)... – Arvind Oct 23 '11 at 10:51
  • Also, how to get a reference to the current window? That would also be very helpful for me... Thanks a lot for your help... – Arvind Oct 23 '11 at 10:52
  • @Arvind The current window can be referenced through `window`. The real window of the current (framed) page can be read using `top`. – Rob W Oct 23 '11 at 10:54