X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Location port Property

Location Object Reference Location Object

Example

Return the port number of the current URL:

var x = "Port: " + location.port;

The result of x will be (If the port number is 80, which is default, nothing will be returned):


Try it yourself »


Definition and Usage

The port property sets or returns the port number the server uses for a URL.

Note: If the port number is not specified in the URL (or if it is the scheme's default port - like 80, or 443), some browsers will display 0 or nothing.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The port property is supported in all major browsers.


Syntax

Return the port property:

location.port

Set the port property:

location.port=port

Value Type Description
port String Specifies the port number of the URL

Return Value

Type Description
String The port number of a URL.

Note: If the port number is not specified or if it is the scheme's default port (like 80 or 443), an empty string is returned


Location Object Reference Location Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook