Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 10th, 2012  |  syntax: None  |  size: 0.55 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to automatically open external links in new tab with PHP redirects?
  2. <a href="http://www.website-shown-browser.com" onclick="this.href='http://'+window.location.host+'/visit/redirect.php'">Website</a>
  3.        
  4. $('a').each(function() {
  5.    var a = new RegExp('/' + window.location.host + '/');
  6.    if(!a.test(this.href)) {
  7.        $(this).click(function(event) {
  8.            event.preventDefault();
  9.            event.stopPropagation();
  10.            window.open(this.href, '_blank');
  11.        });
  12.    }
  13. });
  14.        
  15. $("#content a[href^='http://']").attr("target","_blank");