This one will help you…
var getUrl = window.location;
var baseUrl = getUrl .protocol + "//" + getUrl.host + "/" + getUrl.pathname.split('/')[1];
Resources:
https://stackoverflow.com/questions/25203124/how-to-get-base-url-with-jquery-or-javascript