Skip to content
Recommend our themes and earn 30% of our share of every sale you bring. Free to join.Earn by recommending our themes Become an affiliate

Test if links are external with jQuery

Updated 23 Aug 2018

Source code

<script>
	$(document).ready(function(){
		var base_url = location.protocol + "//" + location.host;
		$("a").not(":contains(" + base_url + ")").click(function(){
			this.target = "_blank";
		});
	});
</script>

More code answers

Comments

Log in to leave a comment.