EDIT:
If you don't need to support IE10, you can simply use: document.location.origin
Original answer, if you need legacy support
You can get all this and more by inspecting the location object:
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:"
}
so:
location.host
would be the domain, in this case stackoverflow.com. For the complete first part of the url, you can use:
location.protocol + "//" + location.host
which in this case would be http://stackoverflow.com
No jQuery required.