Location.hash
The hash property can be set with new values that alter the current URL.
Assume starting at http://www.java2s.com/BOOK/index.htm
location.hash = "#section1";
changes URL to "http://www.java2s.com/BOOK/index.htm#section1"
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
</head>
<body>
<script>
document.location.hash = "section";
</script>
</body>
</html>