You can use the trick by creating <a> -element, then setting the line to href of this <a> element, and then you have a Location Object you can get the path name.
You can either add a method to the String prototype:
String.prototype.toLocation = function() { var a = document.createElement('a'); a.href = this; return a; };
and use it as follows:
css.toLocation().pathname
or make it a function:
function toLocation(url) { var a = document.createElement('a'); a.href = url; return a; };
and use it as follows:
toLocation(css).pathname
both of them will output: "/css/main.css"
source share