JSFiddle - React, Tailwind, and code Playground
JavaScript
function toAbsURL(s) {
var l = location, h, p, f, i;
if (/^\w+:/.test(s)) {
return s;
}
h = l.protocol + '//' + l.host;
if (s.indexOf('/') == 0) {
return h + s;
}
p = l.pathname.replace(/\/[^\/]*$/, '');
f = s.match(/\.\.\//g);
if (f) {
s = s.substring(f.length * 3);
for (i = f.length; i--;) {
p = p.substring(0, p.lastIndexOf('/'));
}
}
return h + p + '/' + s;
}
alert(window.location.href);
alert(toAbsURL('../../'));