Skip to content

Instantly share code, notes, and snippets.

@r4fx
Created October 12, 2014 17:30
Show Gist options
  • Save r4fx/a066d68b376d0226fb67 to your computer and use it in GitHub Desktop.
Save r4fx/a066d68b376d0226fb67 to your computer and use it in GitHub Desktop.
location, url, hash
location = {
host: "stackoverflow.com",
hostname: "stackoverflow.com",
href: "http://stackoverflow.com/questions/2300771/jquery-domain-get-url",
pathname: "/questions/2300771/jquery-domain-get-url",
port: "",
protocol: "http:"
}
location.host // would be the domain
location.protocol + "//" + location.host // complete first part of the url
document.baseURI // gives you the domain + port. It's used if an image tag uses a relative instead of an absolute path
document.baseURI + window.location.hash // complete first part of the url + hash, example: http://stackoverflow.com/#section
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment