JavaScript window.location

window.location properties
Try the following URL for some good examples below: window.location properties
Note: due to use of the explicit port number ":80" in that URL, some browsers will incorrectly report that URL as a potential phishing site and then remove the port number, so the port number may be missing from window.location.port and the values of window.location.href and window.location.host.
window.location propertyUse / Result
get or setStringwindow.location.href
window.location.href = value
the entire URL of the current document
Example:
get or setStringwindow.location.protocol
window.location.protocol = value
the protocol scheme (preceding the "//") from the URL of the current document, including the colon (":")
Example:
get or setStringwindow.location.host
window.location.host = value
the host name or IP address and port number from the URL of the current document
Example:
get or setStringwindow.location.hostname
window.location.hostname = value
the host name or IP address from the URL of the current document
Example:
get or setStringwindow.location.port
window.location.port = value
the port number from the URL of the current document; none indicates it is the default HTTP port number 80
Example:
get or setStringwindow.location.pathname
window.location.pathname = value
the path name from the URL of the current document, starting with the leading slash ("/") that initiates an absolute URL
Example:
Example:
get or setStringwindow.location.hash
window.location.hash = value
the fragment identifier from the URL of the current document, starting with the hash symbol ("#")
Example:
window.location functions
window.location functionUse / Result
Stringwindow.location = url;
window.location.assign(url)
load the document at url and keep the current document in the session history
Example:window.location.assign("/javascript/objects/")
Stringwindow.location.reload()
window.location.reload(forceget)
reload the current document, possibly from cache unless forceget == true
Example:window.location.reload(false)
Stringwindow.location.replace(url)load the document at url and replace the current document in the session history
Example:window.location.replace("/javascript/objects/")