This page is Almost Ready

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

hash

Summary

Sets or retrieves the subsection of the href property that follows the number sign (#).

Property of dom/Locationdom/Location

Syntax

var hash = location.hash;
location.hash = hash;

Return Value

Returns an object of type StringString

The hash component of the URL.

Examples

This example function returns true if the current document URL has a hash value, or false if the document URL does not.

function hasHash() {
    if (document.location.hash === "") {
        return false;
    }
    return true;
}

Notes

If there is no number sign, this property returns an empty string. This property is useful for moving to a bookmark within a document. Assigning an invalid value does not cause an error.

Attributions