If you find this helpful, please click the Google |


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
andwindow.location.host
.
window.location property | Use / Result | |||
---|---|---|---|---|
get or set | String | window.location.href window.location.href = value | the entire URL of the current document | |
Example: | ||||
get or set | String | window.location.protocol window.location.protocol = value | the protocol scheme (preceding the "//") from the URL of the current document, including the colon (":") | |
Example: | ||||
get or set | String | window.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 set | String | window.location.hostname window.location.hostname = value | the host name or IP address from the URL of the current document | |
Example: | ||||
get or set | String | window.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 set | String | window.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: | ||||
get or set | String | window.location.search window.location.search = value | the query string from the URL of the current document, starting with the question mark ("?") | |
Example: | ||||
get or set | String | window.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 function | Use / Result | ||
---|---|---|---|
String | window.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/") | ||
String | window.location.reload() window.location.reload(forceget) | reload the current document, possibly from cache unless forceget == true | |
Example: | window.location.reload(false) | ||
String | window.location.replace(url) | load the document at url and replace the current document in the session history | |
Example: | window.location.replace("/javascript/objects/") |