Skip to content

Instantly share code, notes, and snippets.

@maartenJacobs
Created June 8, 2011 14:38
Show Gist options
  • Save maartenJacobs/1014540 to your computer and use it in GitHub Desktop.
Save maartenJacobs/1014540 to your computer and use it in GitHub Desktop.
BaseUrl simulation where "admin" is your first constant part
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