Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. URL
  4. port

URL: port property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2016.

Note: This feature is available inWeb Workers.

Theport property of theURL interface is a string containing the port number of the URL. If the port is the default for the protocol (80 forws: andhttp:,443 forwss: andhttps:, and21 forftp:), this property contains an empty string,"".

This property can be set to change the port of the URL. If the URL has nohost or its scheme isfile:, then setting this property has no effect. It also silently ignores invalid port numbers.

Value

A string.

Examples

js
// https protocol with non-default port numbernew URL("https://example.com:5443/svn/Repos/").port; // '5443'// http protocol with non-default port numbernew URL("http://example.com:8080/svn/Repos/").port; // '8080'// https protocol with default port numbernew URL("https://example.com:443/svn/Repos/").port; // '' (empty string)// http protocol with default port numbernew URL("http://example.com:80/svn/Repos/").port; // '' (empty string)// https protocol with no explicit port numbernew URL("https://example.com/svn/Repos/").port; // '' (empty string)// http protocol with no explicit port numbernew URL("http://example.com/svn/Repos/").port; // '' (empty string)// ftp protocol with non-default port numbernew URL("ftp://example.com:221/svn/Repos/").port; // '221'// ftp protocol with default port numbernew URL("ftp://example.com:21/svn/Repos/").port; // '' (empty string)

Specifications

Specification
URL
# dom-url-port

Browser compatibility

See also

  • TheURL interface it belongs to.

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp