Instantly share code, notes, and snippets.

@A35G /Base_url.js
Last active Sep 3, 2015

Embed
What would you like to do?
Get the address of the website or web application
function getBaseURL() {
var url = location.href;
var baseURL = url.substring(0, url.indexOf('/', 14));
if (baseURL.indexOf('http://localhost') != -1) {
var url = location.href;
var pathname = location.pathname;
var index1 = url.indexOf(pathname);
var index2 = url.indexOf("/", index1 + 1);
var baseLocalUrl = url.substr(0, index2);
return baseLocalUrl + "/";
} else {
return baseURL + "/";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment