Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.