Skip to content

Instantly share code, notes, and snippets.

@nileshk
Created August 18, 2014 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nileshk/8d4129b10cb2ddb933e8 to your computer and use it in GitHub Desktop.
Save nileshk/8d4129b10cb2ddb933e8 to your computer and use it in GitHub Desktop.
Get current "base" URL (without the document portion or parameters)
// Get current URL without the document portion or parameters
// For example, if the URL is:
// http://hostname:8080/path/to/application/document.html?param1=1&param2=2
// baseUrl will be:
// http://hostname:8080/path/to/application/
var baseUrl = [location.protocol, '//', location.host, location.pathname.split('/').slice(0, -1).join('/'), '/'].join('');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment