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[
jQuery(document).ready(function($){
 $('a[href]:not([href^="http://mywebsite.com"]):not([href^="#"]):not([href^="/"])').attr( 'target', '_blank' );
});
// ]]></script>

Just replace “mywebsite.com” with your domain name

Share it

Last Update: May 23, 2016  

November 24, 2015   521    Website    
Total 1 Votes:
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?