4/11/2012

How to find internal/external links in Web with jQuery

1. Find all internal links

   1:  $("a[href^='/'],a[href*='"+location.hostname+"']") 

2. Find all external links

   1:  $("a[href*='http://']:not([href*='"+location.hostname+"'])") 

--> Using to change style automatic

   1:  $(document).ready(function() {
   2:      $("a[href*='http://']:not([href*='" + location.hostname + "']),[href*='https://']:not([href*='" + location.hostname + "'])").attr("target", "_blank").attr("title", "Opens new window").addClass("external");
   3:   
   4:  });
 

Categories:
If You Enjoyed This Post Please Take 5 Seconds To Share It.

0 comments:

Post a Comment

 
  • I'm a great believer that any tool that enhances communication has profound effects in terms of how people can learn from each other, and how they can achieve the kind of freedoms that they're interested in.

  • Followers