You are here: Reference > JavaScript > client-side > HTML DOM > properties > port (location, a, area)

port property (location, a, area)

Browser support:
Sets or retrieves the port component of the URL assigned to the object.
Use the host property to get the host name, or the hostname property for the host name and port number.


You can find the related objects in the Supported by objects section below.
This property is read/write.

Possible values:

String (number in string format) that specifies or retrieves the port component.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the port property for an anchor:
    <script type="text/javascript">
        function AnalyzeTarget () {
            var anchor = document.getElementById ("myAnchor");

            var message = "";
            message += "hash: " + anchor.hash + "\n";
            message += "host: " + + "\n";
            message += "hostname: " + anchor.hostname + "\n";
            message += "href: " + anchor.href + "\n";
            message += "pathname: " + anchor.pathname + "\n";
            message += "port: " + anchor.port + "\n";
            message += "protocol: " + anchor.protocol + "\n";
            message += "protocolLong: " + anchor.protocolLong + "\n";
            message += "search: " + + "\n";

            alert (message);
    <a href="" id="myAnchor">A sample anchor</a>
    <br /><br />
    <button onclick="AnalyzeTarget ();">Analyze the destination of the anchor above</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content