title: Override window.open()
body: <p>I'm trying to override <code>window.open()</code>, so I'm trying to find a way to open link in new window without <code>window.open()</code>.</p>
  
  <p>In detail, I'm in such a situation: I've got a Silverlight Web Part Which uses <code>HTMLWindow.Navigate()</code> to open hyperlinks in new window, so I cannot use <code>&lt;a&gt;</code> because I've got totally no control to the Web part. The only way is to override <code>window.open()</code>.</p>
  
  <p>For example, when I want to open link in the top window, I override <code>window.open()</code> like this:</p>
  
  <pre><code>window.open = function (open) {
      return function (url, name, features) {
              window.top.location = url;    
              return false;
         };
      }(window.open);
  </code></pre>
  
  <p>Is there a similar method to open link in new window? Thank you very much!</p>
  
  <p>PS: I cannot use anchor here because I'm overriding <code>window.open()</code></p>
  
  <p><strong>What I did finally for this problem:</strong></p>
  
  <p>Firstly, I made a copy of <code>window.open()</code></p>
  
  <pre><code>var _open = window.open;
  </code></pre>
  
  <p>Then I override the <code>window.open()</code> function. Supposing that "target" is a variable that receives querystring, for example. Note that the default behavior is to open the link in the current window.</p>
  
  <pre><code>if (target == "top")
      {
          window.open = function (open) {
              return function (url, name, features) {
                  window.top.location = url;
                  return false;
             };
          }(window.open);
      }
  else if (target == "blank")
  {
      window.open = function (open) {
              return function (url, name, features) {
                  return open_(url, '_blank', features);
             };
          }(window.open);
  }
  </code></pre>