Window location.hash attribute
- Previous page assign()
- Next page host
- Go back one level Window Location
Definition and usage
location.hash
The attribute sets or returns the anchor part of the URL, including the hash (#).
Tip:When location.hash is used to set the anchor part, do not include the hash symbol (#).
Example
Example 1
Get the anchor part of the URL:
<a href="/js/js_strings.asp#part2">JavaScript Strings</a>
Example 2
Set anchor part:
location.hash = "part5";
Syntax
Return hash attribute:
location.hash
Set hash attribute:
location.hash = anchorname
Parameter
Parameter | Description |
---|---|
anchorname | The anchor part of the URL. |
Return value
Type | Description |
---|---|
String | The anchor part of the URL, including the hash (#). |
Browser support
All browsers support location.hash
:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support | Support |
- Previous page assign()
- Next page host
- Go back one level Window Location