This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

window.location.hash

Summary

The hash property contains the fragment identifier (including hash character) for the current page.

Property of apis/locationapis/location

Syntax

var result = window.location.hash;
window.location.hash =
#foo;

Return Value

Returns an object of type StringString

Returns the fragment identifier (including hash character) for the current page.

For example, http://example.org/#foo would return the fragment identifier of #foo.

Examples

This example shows how to first check for the availability of the window.location.hash property, and then checks to see whether the second tab in our fictional web app should be displayed.

if(typeof window.location.hash != "undefined" && window.location.hash == "#tab2"){
    // Code to display the second tab goes here.
}

Usage

 This property is used to see what the fragment identifier, or "hash" is for the current page is set to.

Notes

The window.location.hash property does not work in versions of Internet Explorer prior to version 8.

This is most often used to preserve permalinks in web applications, however the history API may be better suited to this task if legacy browser support is not required.

Related specifications

Window Object 1.0
W3C Working Draft