Location.hash

In this chapter you will learn:

  1. How to use Location.hash property

Hash of location

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

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

location.hash = "#section1";

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

<!DOCTYPE HTML> // ja v  a2s . c o m
<html> 
    <body> 
        <script> 
                document.location.hash = "section"; 
        </script> 
    </body> 
</html>

Next chapter...

What you will learn in the next chapter:

  1. How to change the hostname of location
Home » Javascript Tutorial » Location
Location
assign method
Location.hash
Location.hostname
Location.href
location.pathname
location.port
location.reload
location.replace()
Location.search