JavaScript window.location.port Property

You are Here:

JavaScript window.location.port Property

The window.location.port property returns a string containing the port number of the current page.

Note: If the URL does not contain an explicit port number, it will be set to ''. For example, wikimass.com is running in port 80 (http port) which is default for any website, so port number will not be displayed for port 80 as it doest not contain any explicit port.

The following table lists common ports and their security modes:

ProtocolNo encryption
Plain port
TLS/SSL
Explicit port
TLS/SSL
Implicit port
FTP2121990
SMTP25 or 58725 or 587993
IMAP143143993
POP3110110995
Telnet2323992
HTTP80-443

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> document.write("Port number: "+window.location.port); </script> </body> </html>

Syntax

window.location.port

Return Value

ValueExplanation
StringReturns a string containing the port number of the current page.

More Examples

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var txt = ""; txt += "<p>Page location: "+window.location.href+"</p>"; txt += "<p>Page hostname: "+window.location.hostname+"</p>"; txt += "<p>Page path: "+window.location.pathname+"</p>"; txt += "<p>Page protocol: "+window.location.protocol+"</p>"; txt += "<p>Port number: "+window.location.port+"</p>"; document.write(txt); </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author