Location.hash

JavaScript 1.0+, JScript 1.0+ Nav2+, IE 3+, Opera3+ Syntax

location.hash

Description

The hash property of the Location object refers to the anchor portion of the URL, including the hash symbol (#).

In the following fictitious Web address:

http://www.mcp.com:80/foo?something#foobar

the hash value would be the #foobar portion.

Example

Listing 7.380 shows an example of how to get the hash value.

Listing 7.380 Example of the hash Property
<html>
<head>
<title> Using the hash property of the Location object</title>
</head>
<body>

<script language="JavaScript">
<!-- Hide
							 // displays the anchor portion of the URL function show(){ document.form1.text1.value=document.location.hash; } // End Hide ---> </script> <form name="form1"> ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.