How to use Location.hash property in Javascript

Hash of location

The hash property can be set with new values that alter the current URL.

Example

Assume starting at http://www.java2s.com/index.htm

location.hash = "#section1";

changes URL to "http://www.java2s.com/index.htm#section1"


<!DOCTYPE HTML> 
<html> 
    <body> 
        <script> 
                document.location.hash = "section"; 
        </script> 
    </body> 
</html>




















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window