0 Replies - 987 Views - Last Post: 17 May 2011 - 07:08 AM

#1 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1014
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

[jQuery] Find External Links

Posted 17 May 2011 - 07:08 AM

Description: This snippet extends the standard JQuery, and add a new selector, external, to find external links.
$.extend(
    $.expr[':'].external = function(obj){
        if(obj.hostname == location.hostname){
            return false;
        }
        return true;
});

/***************
Example for use, open all external links in new window
i.e, add target _blank to all external links:
***************/
$(document).ready(function(){
    $('a:external').each(function(){
        $(this).attr("target", "_blank");
    });
});


Is This A Good Question/Topic? 0
  • +

Page 1 of 1