External Links | jQuery Open Link in New Window

jquery open link in new window
This is a jQuery code snippet that changes the behavior of each external link to open in a new window.
You can easily implement it on your website or a single webpage.

Code Example External Links jQuery Open Link In New Tab

$('a').each(function() {
   var a = new RegExp('/' + window.location.host + '/');
   if(!a.test(this.href)) {
       $(this).click(function(event) {
           event.preventDefault();
           event.stopPropagation();
           window.open(this.href, '_blank');
       });
   }
});

Or on the other hand, you can even now keep away from the approval issues and simply add the class target=_blank thing to any connections with href characteristics beginning with http://.

The model beneath just targets connects in a #content zone. Checking down like that may be a smart thought on the off chance that your menus are dynamic and make full URLs.

$("#content a[href^='http://']").attr("target","_blank");

SUBSCRIBE TO OUR NEWSLETTER

Hellodearcode is Web Development agency providing services for Wordpress and Laravel

0 Response to "External Links | jQuery Open Link in New Window"

Post a Comment

Note: only a member of this blog may post a comment.