How to open all external links in a new window?

In your website you might want to open all external links in a new window so your visitors won’t leave your site. You can insert the target=”_blank” attribute to each link individually but it might forget some of them or it can be more difficult if you are using scripts.

Insert this script snippet into your footer and all links will automatically open in a new window or tab, depending on the visitor’s browser setting:

<script type="text/javascript">// <![CDATA[
 $('a[href]:not([href^=""]):not([href^="#"]):not([href^="/"])').attr( 'target', '_blank' );
// ]]></script>

Just replace “” with your domain name

Share it

Last Update: May 23, 2016  

November 24, 2015   611    Website    
Total 1 Votes:

Tell us how can we improve this post?

+ = Verify Human or Spambot ?