Created
June 8, 2011 14:38
-
-
Save maartenJacobs/1014540 to your computer and use it in GitHub Desktop.
BaseUrl simulation where "admin" is your first constant part
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
var baseUrl = function(){ | |
// Calculate base url by filtering on the parts | |
var parts = location.pathname.split('/'), | |
base = '', | |
i, | |
max; | |
for (i = 0, max = parts.length; i < max; i++) { | |
if(parts[i] === 'admin'){ | |
break; | |
} else if(parts[i] === ''){ | |
continue; | |
} else { | |
base += '/' + parts[i]; | |
} | |
} | |
// Redefines the variable so it never has to get the base url again | |
baseUrl = function(){ | |
return base; | |
} | |
return baseUrl(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment