title: How can I check for an open URL in another window?
body: <p>This is a follow up to my last question <a href="https://stackoverflow.com/questions/528671/javascript-window-open-only-if-the-window-does-not-already-exist">Open a window if the window does not already exist</a>
  Essentially, I am now keeping a list of all the window references that have been opened by a page, and only allowing them to be opened if they are not already open. Then a potential problem struck me - it is of course possible for a user to shut down the original window, and open it again, thus losing the list of window references.</p>
  
  <p>Is it possible to loop through the windows open in a browser, checking for a particular URL?</p>
  
  <p>Edit:
  After a lot of helpful comments here (and on the other question), here is the final code for the application launcher. Essentially, it tries to get the location of the open window with the appropriate name. If that causes an exception (because of a privacy issue), then the application is judged to have been loaded. If it is "about:blank", then it is a new window. This works on Firefox, IE7 and Google Chrome. It feels dirty...</p>
  
  <pre><code>var g_urlarray = [];
  
  Array.prototype.has = function(value) {
      var i;
      for (var i in this) {
          if (i === value) {
              return true;
          }
      }
      return false;
  };
  
  
  function launchApplication(l_url, l_windowName)
  {
      var l_width = screen.availWidth;
      var l_height = screen.availHeight;
      var winRef;
  
      var l_params = 'status=1' +
          ',resizable=1' +
          ',scrollbars=1' +
          ',width=' + l_width +
          ',height=' + l_height +
          ',left=0' +
          ',top=0';
      if (g_urlarray.has(l_url)) {
          winRef = g_urlarray[l_url];
      }
      if (winRef == null || winRef.closed) {
          winRef = window.open('', l_windowName, l_params);
          var l_openNew = 0;
          try {
              if (winRef.location == 'about:blank') {
                  l_openNew = 1;
              }
          }
          catch (e) {
              l_openNew = 0;
          }
          if (l_openNew === 1)
          {
              winRef.location = l_url;
              winRef.moveTo(0,0);
              winRef.resizeTo(l_width, l_height);
          }
          g_urlarray[l_url] = winRef;
      }
  }
  </code></pre>