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>
  
Click to view the demo

Changing the value of hash causes a new entry in the browser's history to be recorded.

Home 
  JavaScript Book 
    DOM  

Location:
  1. The Location Object
  2. To get information about the location of the current page
  3. Location assign()
  4. Location.hash
  5. Location.hostname
  6. Location.href
  7. location.pathname
  8. location.port
  9. location.reload()
  10. location.replace()
  11. Location.search
  12. Query String Arguments