var getAbsoluteUrl = (function() { var a; return function(url) { if(!a) a = document.createElement('a'); a.href = url; return a.href; }; })(); // Test console.log(getAbsoluteUrl("/some-relative-url"));
<html> <body> Check the console to see the output of getAbsoluteUrl("/some-relative-url") </body> </html>
body { font-family: arial; }