URL: port プロパティ

Baseline Widely available

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

メモ: この機能はウェブワーカー内で利用可能です。

portURL インターフェイスのプロパティで、この URL のポート番号の入った文字列です。

メモ: URL() コンストラクターに渡された入力文字列が明示的なポート番号を含んでいないか(例えば https://localhost)、入力文字列のプロトコル部分に対応する既定のポート番号を含んでいる場合(例えば https://localhost:443)、コンストラクターが返す URL オブジェクトの port プロパティの値は空文字列 ('') になります。

文字列です。

js
// https プロトコルで既定ではないポート番号
new URL("https://example.com:5443/svn/Repos/").port; // '5443'
// http プロトコルで既定ではないポート番号
new URL("http://example.com:8080/svn/Repos/").port; // '8080'
// https プロトコルで既定のポート番号
new URL("https://example.com:443/svn/Repos/").port; // ''(空文字列)
// http プロトコルで既定のポート番号
new URL("http://example.com:80/svn/Repos/").port; // ''(空文字列)
// https プロトコルで明示的なポート番号なし
new URL("https://example.com/svn/Repos/").port; // ''(空文字列)
// http プロトコルで明示的なポート番号なし
new URL("https://example.com/svn/Repos/").port; // ''(空文字列)
// ftp プロトコルで既定ではないポート番号
new URL("ftp://example.com:221/svn/Repos/").port; // '221'
// ftp プロトコルで既定のポート番号
new URL("ftp://example.com:21/svn/Repos/").port; // ''(空文字列)

仕様書

Specification
URL
# dom-url-port

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
port

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報

  • 所属先の URL インターフェイス