Get $_SERVER[‘HTTP_HOST’] by javascript / get absolute path of server file script

Get $_SERVER[‘HTTP_HOST’] by javascript / get absolute path of server file script

function getAbsolutePath() {
    var loc = window.location;
    var pathName = loc.pathname.substring(0, loc.pathname.lastIndexOf('/') + 1);//to get path of current url
    return loc.href.substring(0, loc.href.length - ((loc.pathname + loc.search + loc.hash).length - pathName.length));
}

Share on Facebook



One thought on “Get $_SERVER[‘HTTP_HOST’] by javascript / get absolute path of server file script”