Blog

25 Latest Articles
14

Selecting outbound links with jQuery

Maps on Kindle has a great article about using jQuery to select all outbound links on your web site.  In a nutshell, it creates a new selector by comparing the url of the link to the domain of the current web page.  That allows you to do things like this:

$('a:external').css('color', '#F00');

Pretty cool, right?

Unfortunately, there was a small oversight in their code, which I hope to rectify here.

In the original source, the code didn't account for the www problem.  If the visitor is looking at www.this.com/page [with the www.], and a link on the page points to this.com/something [without the www.], the script will consider it an outbound link.

To fix this, I've added a small tweak:


$.expr[':'].external = function(obj){
   return !obj.href.match(/^mailto:/) &&
      (obj.hostname.replace(/^www\./i, '') != document.location.hostname.replace(/^www\./i, ''));
};

Just add this to your JavaScript inside the $(document).ready(...) and you're all set.

Enjoy!

 

12

Introducing Colortoons CHIKARA!

The cast of CHIKARA comes to Colortoons complete with entrance themes, photos, over 40 exclusive videos and a whole lot more! Colortoons is an intera...

Read more....

05

Steve Jobs, 1955 - 2011

Ben Franklin.  Thomas Edison.  Henry Ford.  Steve Jobs. The Mt. Rushmore of American Innovation.
03

Introducing Colortoons Halloween!

Halloween has come to Colortoons! Colortoons Halloween is an interactive coloring book for the iPhone, iPad and iPod Touch.  With just a touch o...

Read more....

29

Why Amazon Silk Should Scare You

Fire by Chris Espinosa Amazon will capture and control every Web transaction performed by Fire users.  Every page they see, every link they foll...

Read more....

Page 1 of 6First   Previous   [1]  2  3  4  5  6  Next   Last