port属性设置或返回URL的端口。
注意:如果未在URL中指定端口号或它是方案的默认端口(例如80或443),则port属性将返回一个空字符串。
返回端口属性:
location.port
设置端口属性:
location.port = port
document.write("The port number is: " + location.port);测试看看‹/›所有浏览器完全支持port属性:
| 属性 |  |  |  |  |  | 
| port | 是 | 是 | 是 | 是 | 是 | 
| 值 | 描述 | 
|---|---|
| port | 字符串,指定URL的端口号 | 
| 返回值: | 一个字符串,表示URL的端口号 | 
|---|
位置参考:location.href属性
位置参考:location.host属性
位置参考:location.origin属性
位置参考:location.protocol属性