Latest web development tutorials

Location port property

Location Object Reference Location Object

Definition and Usage

port property is a readable and writable string sets or returns the port portion of the current URL.

Note: If the port number is 80 (which is the default port number), without specifying.

grammar

location.port


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support port property


Examples

Examples

Returns the port number of the current URL:

<script>

document.write(location.port);

</script>

Examples of the above output:


try it"


Location Object Reference Location Object