views:

95

answers:

1

I'm trying to see which windows are being opened, but I dont know the window names as they are called.

How can I access them in JAVASCRIPT/DOM/or JQUERY?

Thanks!

+3  A: 

Every example I've seen requires the name of the window. If you can't control that yourself, because you're using a complicated/obfuscated library or a generic greasemonkey script for a complicated website, say, you could try and monkey patch the places the window is opened. Assuming windows are all opened via window.open, you could do:

var allWindows = []
var _windowOpen = window.open;
window.open = function() {
  var newWindow = _windowOpen.apply(this, arguments);
  allWindows.push(newWindow);
}

allWindows will then contain the list of all windows that have been opened so far. You can loop through them at any time and check the "closed" property to find those that are still open. i.e. you deduce a window is open if !win.closed.

mahemoff
thanks I'll try this and let you know how it goes =]
codeninja
ok that didnt work too well. it just opened the popup in a new window =/
codeninja
Yes, that's what it should do, if any code calls window.open. did you check allWindows? I've tried it and the new window will go into the allWindows array.
mahemoff
Thanks. the script you provided did help. but i found out that two successive calls to window.open in ie6 causes the problem. the first call to window.open doesnt load all the way before window.open is called again, essentially haulting execution of the first window. essentially only the second window loads... this is the problem as it stands now that i need to resolve
codeninja
Again - if you're not the one making the calls - you could try monkey patching to avoid opening the window again too quickly. in the above window.open redefinition, set a timer to track whether a window might currently be opening. Or make allWindows into an object/map so you can track which URLs are currently open and ensure each URL is only opened once. Depends on the problem at hand.
mahemoff