title: JavaScript window.open only if the window does not already exist
body: <p>I have an application that opens a new window on clicking a link. This spawns a page that holds a Java applet. The problem I am having is that clicking the same link reloads the page, which resets the Java application. Is there any way to trap this? Two solutions that would be acceptable are:</p>
  
  <ol>
  <li>Allow multiple windows to be opened from the click handler</li>
  <li>Ignore subsequent requests if the window is already open</li>
  </ol>
  
  <p>Apologies for being a Javascript newbie - it's not really my main thing.</p>
  
  <p>The code attached to the handler is</p>
  
  <pre><code>function launchApplication(l_url, l_windowName)
  {
    var l_width = screen.availWidth;
    var l_height = screen.availHeight;
  
    var l_params = 'status=1' +
                   ',resizable=1' +
                   ',scrollbars=1' +
                   ',width=' + l_width +
                   ',height=' + l_height +
                   ',left=0' +
                   ',top=0';
  
    winRef = window.open(l_url, l_windowName, l_params);
    winRef.moveTo(0,0);
    winRef.resizeTo(l_width, l_height);
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>Thanks for the replies - I modified the suggestions slightly so that I could have more than one URL opened via the function.</p>
  
  <p>EDIT2:
  There is another version of this code at <a href="https://stackoverflow.com/questions/528941/how-can-i-check-for-an-open-url-in-another-window">Check for a URL open on another window</a></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];
    }
    alert(winRef);
    if (winRef == null || winRef.closed) {
        winRef = window.open(l_url, l_windowName, l_params);
        winRef.moveTo(0,0);
        winRef.resizeTo(l_width, l_height);
        g_urlarray[l_url] = winRef;
    }
  }
  </code></pre>