JavaScript: getAbsoluteUrl

Published on Author craigzearfossLeave a comment
/*
Returns the absolute url.

Usage:
    getAbsoluteUrl('/something');

    http://davidwalsh.name/something

reference: http://davidwalsh.name/essential-javascript-functions
*/

var getAbsoluteUrl = (function() {
   var a;

   return function(url) {
       if(!a) a = document.createElement('a');
       a.href = url;

       return a.href;
   };
})();

Leave a Reply

Your email address will not be published. Required fields are marked *