söndag 27 februari 2011

Code Snippet: Open External Links In New Window

You can do this straight with HTML, but that is invalid markup, this takes care of business without invalid code and unnecessary markup.

$('a').each(function() {
   var a = new RegExp('/' + window.location.host + '/');
   if(!a.test(this.href)) {
       $(this).click(function(event) {
           event.preventDefault();
           event.stopPropagation();
           window.open(this.href, '_blank');
       });
   }
});

Code snippet: Find all Internal Links

Find all links that start with the sites domain, a slash, relative file path, or a hashtag.

var siteURL = "http://" + top.location.host.toString();
var $internalLinks = $("a[href^='"+siteURL+"'], a[href^='/'], a[href^='./'], a[href^='../'], a[href^='#']");

My Depot

Welcome to my depot. here i will put something about anything. I will write down all things i can about anything.
It can be code snippets and otherstuff