title: Javascript to rewrite all external links on mousedown?
body: <p>How can i rewrite all <strong>external links</strong> with a single onmousedown event? </p>
  
  <p>Kinda like what facebooks does with it's link shim </p>
  
  <p><strong>Please check the original Facebook Article about the link shim</strong>: 
  <a href="http://on.fb.me/zYAq0N" rel="nofollow">http://on.fb.me/zYAq0N</a></p>
  
  <p><strong>Requirements:</strong></p>
  
  <ul>
  <li><p>Should work for all subdomains on mainsite.com.</p></li>
  <li><p>Should redirect example.com to
  mainsite.com/link.cgi?u=http://example.com</p></li>
  <li><p>Should only redirect links not belonging to mainsite.com.</p></li>
  </ul>
  
  <p><strong>Uses:</strong></p>
  
  <p>This is for security of the users of a private web app, and to protect referrers.</p>
  
  <p>Best to do it on the fly for good UI as pointed out in the FB article.</p>
  
  <p>That's so when users hovers over some link it shows the correct link but when he clicks it, js redirects it to my.site.com/link.cgi=http://link.com</p>
  
  <p>Thanks in advance</p>
  
  <p><strong>SOLVED</strong>: <a href="https://gist.github.com/2342509" rel="nofollow">https://gist.github.com/2342509</a></p>