Auto set target=“_blank” to open external links in new tab

Written on 04 July 2016

If you use Markdown or WYSIWYG editor open external link in new tab is a rule for your site.
You can set target="blank" in every external link

<a href="http://example.com/" target="_blank">Hello, world!</a>  

But you can do this automatically use javacript bellow.

<script>  
var links = document.links;  
for (var i = 0, linksLength = links.length; i < linksLength; i++) {  
   if (links[i].hostname != window.location.hostname) {
       links[i].target = '_blank';
   } 
}
</script>  
Read more on HTML Link External blank Auto