Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Getting every window as an Array?

  1. #1
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default Getting every window as an Array?

    I was wondering if you could get an array or something of every window, or an array of the names. I was looking at some of Firefox's js and they had some stuff for tabs that was like,
    Code:
    this._windows[<something goes here>]
    but when I tried it, it didn't work. Any other possibilities?

  2. #2
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    var windows = [window];
    for(var i=0; i<window.frames.length; ++i) windows.push(window.frames[i]);
    Trinithis

  3. #3
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    Oh, and when you open a new window through window.open(), add the new window to the array.
    Trinithis

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You can override window.open to do that automatically:
    Code:
    open = (function(oldopen) {
      return function() {
        return (windows[windows.length] = oldopen.apply(window, arguments));
      };
    })(open);
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    Wait, it says that window.frames.length is equal to 0, so how does that work?

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    That just means you have no frames on the page.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    Frames? I was wondering about other browser windows. How do frames play in? I had some tabs open.

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    A frame, if it exists, is a window object.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    Well then does that work in reverse? Were if a window exits its part of window.frames? Because I don't want every frame, I want every window.

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    No, a full window is not a part of the window.frames object. If you don't want any frames or iframes, the window.frames object may be excluded. I haven't been following this thread closely so, I'm not sure if it would have to be actively excluded or merely remove from consideration. Most likely you could just leave it out, testing would be a good idea though.

    However, if you leave out frames, you do not technically have all 'windows'. This may come back to haunt you at some point, or not.

    Additionally, windows not created with javascript and not existing as frames in the window the code in this thread is on, would not be included in the array. I don't think there is any way to just get all windows, like if the user arrives at your page with several windows open from another domain or domains, as far as I know, those cannot be found or counted with javascript on your page.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •