Open External Links in a New Window using JQuery

#frontend #javascript #jquery

Looking for a quick and dirty way to open all external links in a new window? The below snippet of code will make all links to external websites open in a new window:

$("a[href*='https://']").attr('target','_blank');

Using the ‘*=’ selector on the href attribute, you can match any link containing http:// and set the target attribute to ‘_blank’.

Hope this tip helps!