Location hash Property - Javascript Browser Object Model

Javascript examples for Browser Object Model:Location

Description

The hash property sets or gets the anchor part of a URL, including the hash sign (#).

When setting the anchor part, do not include the hash sign (#).

Set the hash property with the following Values

Value Type Description
anchorname String Sets the anchor part of a URL

Return Value

A String, representing the anchor part of the URL, including the hash sign (#)

The following code shows how to Return the anchor part of a URL.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*  w w w.  j ava 2  s  . co m*/
    var v = location.hash;
    document.getElementById("demo").innerHTML = v;
}
</script>

</body>
</html>

Related Tutorials