How to change the port for location object in Javascript

Port

The port property can be set with new values that alter the current URL. assume starting at http://www.java2s.com/

location.port = "8080";

changes URL to "http://www.java2s.com:8080/

Example


<!DOCTYPE HTML> 
<html> 
    <body> 
        <script> 
               location.port = "8080"; 
        </script> 
    </body> 
</html><!--  w  ww .  java 2  s  . com-->

Click to view the demo

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





















Home »
  Javascript »
    Javascript Reference »




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