Created
November 22, 2013 13:50
-
-
Save abelrgr/7600152 to your computer and use it in GitHub Desktop.
Get Base URL
From http://arifhossen.wordpress.com/2010/07/19/javascript-get-base-url/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getBaseURL() { | |
var url = location.href; // entire url including querystring - also: window.location.href; | |
var baseURL = url.substring(0, url.indexOf('/', 14)); | |
if (baseURL.indexOf('http://localhost') != -1) { | |
// Base Url for localhost | |
var url = location.href; // window.location.href; | |
var pathname = location.pathname; // window.location.pathname; | |
var index1 = url.indexOf(pathname); | |
var index2 = url.indexOf("/", index1 + 1); | |
var baseLocalUrl = url.substr(0, index2); | |
return baseLocalUrl + "/"; | |
} | |
else { | |
// Root Url for domain name | |
return baseURL + "/"; | |
} | |
} | |
//llamamos a la funcion | |
document.write(getBaseURL()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment