window.location.pathname will get you the directory, as well as the page name. You could then use .substring() to get the directory:
var loc = window.location.pathname;
var dir = loc.substring(0, loc.lastIndexOf("https://stackoverflow.com/"));
window.location.pathname will get you the directory, as well as the page name. You could then use .substring() to get the directory:
var loc = window.location.pathname;
var dir = loc.substring(0, loc.lastIndexOf("https://stackoverflow.com/"));