Over a million developers have joined DZone.

Use JQuery To Make All External Links Open In A New Window/tab

·
This Javascript snippet will make it so that all external links will open in a new window or tab.


$(document).ready(function() {
   $("a[href^=http]").each(function(){
      if(this.href.indexOf(location.hostname) == -1) {
         $(this).attr({
            target: "_blank",
            title: "Opens in a new window"
         });
      }
   })
});
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}