location.port
The port property can be set with new values that alter the current URL.
assume starting at http://www.java2s.com/BOOK/
location.port = "8080";
changes URL to "http://www.java2s.com:8080/BOOK/
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
</head>
<body>
<script>
location.port = "8080";
</script>
</body>
</html>
Changing the value of hash causes a new entry in the browser's history to be recorded.