JS DOM: Get URL (window.location)
What is window.location
The window.location object contains URL info. You can use it like this:
window.location.href
window.location Properties
The window.location object has the following properties. Their values are string.
href-
Entire URL. e.g.
http://example.com/4960/p?tn=1&wvr=5. If you setwindow.location.href, browser will load it. protocol-
Protocol. e.g.
http://,ftp://,file:// host-
The host name and port number (if the URL has port number). e.g.
www.example.com:8080or empty string. hostname-
Host name. e.g.
www.example.com origin-
Origin. e.g.
http://www.example.comor"null" port-
Port number. e.g.
8080 pathname-
Pathname, with beginning slash. e.g.
/js/js_get_url.html search-
Part of URL after
?, including?. e.g.?topnav=1&wvr=5γsee Update URL Paramγ hash-
The part of url after
#, including#. e.g.#hoot