English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
portProperty sets or returns the port of the URL.
Note:If the port number is not specified in the URL or it is the default port of the scheme (for example80 or443),then the port property will return an empty string.
Return Port Property:
location.port
Set Port Property:
location.port = port
document.write("The port number is: " + location.port);Test See‹/›
All browsers fully support the port property:
Property | |||||
port | Yes | Yes | Yes | Yes | Yes |
Value | Description |
---|---|
port | A string specifying the port number of the URL |
Return Value: | A string representing the port number of the URL |
---|
Location Reference:location.href property
Location Reference:location.host property
Location Reference:location.origin property
Location Reference:location.protocol property