I am looking for plain JavaScript code (no jQuery etc.) to learn the directory path component of my currently loaded page\'s URL.
For instance, if my page is loaded
It looks like this does the trick:
var href = window.location.href;
var dir = href.substring(0, href.lastIndexOf('/')) + "/";
Is this a safe method or can this fail with more complex URLs?
Highlighting the comment in the question that helped me:
Phylogenesis's comment:
The simple solution is location.href.replace(/[^/]*$/, ''); then.