When training new clients on how to edit their own websites in wordpress, I often mention the convention of ‘targeting blank’ when linking to another website. Adding the ‘target=”_blank”‘ tag to the link opens a new window when the user clicks the link, leaving the client website open in the background . Still, I know clients will forget this so I often add a little JavaScript code to make sure the links are always set to target blank:
Since I know all my wordpress sites include jQuery, I use that library to make the call as compact as possible:
CODE:
$(document).ready(function() {
$(“a[href^=’http:’]”).
not(“[href*=’CLIENTDOMAIN.COM’]”).
attr(‘target’,’_blank’);
});
what does it do? it finds all links that start with http:, then filters out (not) those links that go to the CLIENTDOMAIN.COM (their domain name), then it sets the ‘target’ attribute to ‘_blank’, linking all external links on the