The port
property sets or gets the port
number for a URL.
port |
Yes | Yes | Yes | Yes | Yes |
Return the port property.
var v = location.port
Set the port property.
location.port=port
Value | Type | Description |
---|---|---|
port | String | Set the port number of the URL |
A String type value representing the port number of a URL.
The following code shows how to get the port number of the current URL.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!-- w ww .jav a 2s. co m-->
var x = "Port: " + location.port;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: