Open In App
Related Articles

HTML DOM Location port Property

Improve Article
Save Article
Like Article

The HTML DOM Location Port property returns or sets the port number of the current URL. 


  • Get the port property:
  • Set the port property:

Property Value:

  • A String, to be assigned as a port

Return Value:

  • A String represents the port number of a URL.

Example: In this example, we will use the HTML DOM Location Port.


<!DOCTYPE html>
    <p id="demo"></p>
    <p><b>Note: </b>If the port number is default
        (80 for http and 443 for https),
        most browsers will display 0 or nothing.
        const url = document.createElement('a');
        url.setAttribute('href', '');
        <!-- Return Location port Property -->
        window.alert("The URL port number of the current page is: "
            + url.port);



Supported Browsers:

  • Google Chrome 1
  • Edge 12
  • Internet Explorer 3
  • Firefox 1
  • Opera 12.1
  • Safari 1
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 14 Jun, 2023
Like Article
Save Article
Similar Reads
Complete Tutorials