window.location.port
Summary
The port number the document was accessed via.
Property of apis/locationapis/location
Syntax
Note: This property is read-only.
var result = window.location.port;
Return Value
Returns an object of type
The port number the document was accessed via.
For example, http://example.org/
would return the default HTTP port number of 80
.
Examples
The following example assumes your document has a div element with id 'hostDiv’, like this.
// Get the port from window.location
var host = window.location.port;
// Get a div element with id 'hostDiv'
var container = document.getElementById('hostDiv');
// Fill in the div element with the port
container.innerHTML = port;
Related specifications
- Window Object 1.0
- W3C Working Draft