jQuery: How to open specific links in new tab having specific url?

Just put following code in your javascript file and It will pick all links globally from your website and will open them in a new tab. Don’t forget to replace url with your own website’s url.

$(document).ready(function(){
    $('a[href*="website.com"] ').click(function(e) {
    	e.preventDefault();
        window.open(this.href, '_blank');
        return false;
    });
});

 

Leave a Reply

Your email address will not be published. Required fields are marked *