Skip to content

Instantly share code, notes, and snippets.

@oskarkrawczyk
Created June 10, 2009 15:21
Show Gist options
  • Save oskarkrawczyk/127279 to your computer and use it in GitHub Desktop.
Save oskarkrawczyk/127279 to your computer and use it in GitHub Desktop.
Returns all links that are not on the same domain as the website is.
/* Returns all links that are not on the same domain as the website is.
*
* $$('a:external') - Automatically checks for the domain name
* $$('a:external(example.com)') - Set a custom, base domain
*
* Example:
*
* $$('a:external').each(function(popup) {
* popup.addEvent('click', function(e) {
* e.stop();
* window.open(this.get('href'), '_blank').focus();
* });
* });
*
* Author: Oskar Krawczyk (oskar dot krawczyk dot com after nouincolor)
*/
$extend(Selectors.Pseudo, {
external: function(domain) {
domain = $pick(domain, window.location.host.toString());
return (!$(this).get('href').contains(domain) && !$(this).get('href').contains('#'));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment