title: javascript function on a window object, when invoked, replaces that window's contents? (sometimes??)
body: <p>For reasons which shall not be enumerated here, I've found it potentially useful to attach functions to the window object. However, I've discovered rather weird behavior.</p>
  
  <pre><code>&lt;html&gt;&lt;head&gt;&lt;script&gt;
  function sideEffect() { console.log("Side effect happened. Wewt."); }
  window.foo = function() {
      sideEffect();
      return true;
  }
  window.bar = function() {
      sideEffect();
  }
  &lt;/script&gt;&lt;/head&gt;
  &lt;body&gt;
  &lt;a href="javascript:window.foo();"&gt;Replaces entire window with "true"&lt;/a&gt;
  &lt;br /&gt;
  &lt;a href="javascript:window.bar();"&gt;Doesn't&lt;/a&gt;
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>Why exactly does invoking a function with a return value decide to replace the window's contents? This happens in Firefox and Opera, but not in IE9, Chrome, or Safari (all tested on Win7).</p>
  
  <p>So the question is this: Is there some sort of documentation that specifies this behavior?
  Or is this a (known) bug in FF/Opera?</p>
  
  <hr>
  
  <p>[edit] Interestingly (according to answers and comments thusfar) it appears that the abuse of the <code>window</code> object is a red herring here.</p>