Location: port-Eigenschaft

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.

Die port-Eigenschaft des Location-Interfaces ist ein String, der die Portnummer der URL des Standorts enthält. Wenn der Port der Standardport für das Protokoll ist (80 für ws: und http:, 443 für wss: und https:, und 21 für ftp:), enthält diese Eigenschaft einen leeren String, "".

Diese Eigenschaft kann festgelegt werden, um den Port der URL zu ändern. Wenn die URL keinen host hat oder das Schema file: ist, hat das Festlegen dieser Eigenschaft keine Wirkung. Ungültige Portnummern werden ebenfalls stillschweigend ignoriert.

Weiterführende Informationen finden Sie unter URL.port.

Wert

Ein String.

Beispiele

js
// Assume current page is at https://developer.mozilla.org/en-US/docs/Location/port
const result = location.port; // Returns:''
js
// Assume another page is at https://developer.mozilla.org:8888/en-US/docs/Location/port
const result = location.port; // Returns:'8888'

Spezifikationen

Specification
HTML
# dom-location-port-dev

Browser-Kompatibilität

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
port

Legend

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

Full support
Full support
No support
No support
User must explicitly enable this feature.