Location portProperty

Location 对象参考手册Location Object

Definition and Usage

The port property is a readable and writable string that can set or return the port portion of the current URL.

Note:If the port number is 80 (which is the default port number), it does not need to be specified.

Syntax

location.port


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the port property.


Example

Example

Return the port number of the current URL:

<script>

document.write(location.port);

</script>

The output of the above example is:


Try it yourself »


Location 对象参考手册Location Object Other Extensions