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

 
  • Followers