Export (0) Print
Expand All
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

port property

Sets or retrieves the port number associated with a URL.

Syntax

JavaScript

p = object.port

Property values

Type: String

the port number associated with the URL. See remarks.

Remarks

The port will resolve based on the default port for the protocol set in the HREF attribute: 21 for FTP, 80 for HTTP, and so forth.

Proprietary protocols that do not require a port return 0 or an empty string.

location.port returns an empty string when read in a page reached by the http protocol.

Examples

This example function returns the port property of two a elements.


<!DOCTYPE html>

<html>
<head>
  <title>Port</title>

</head>
<body>
  <p>Click a link:</p>
  <a href="ftp://www.microsoft.com" onclick="getPort(this);">ftp</a>
  <a href="http://www.microsoft.com" onclick="getPort(this);">http</a>

  <script>
    function getPort(evt) {
      console.log("FTP: " + evt.port + "\n" + "HTTP: " + evt.port);
    }
  </script>
</body>
</html>

See also

a
area
location

 

 

Show:
© 2014 Microsoft