Skip to content

Commit

Permalink
fixes #35732, update port description & fix example
Browse files Browse the repository at this point in the history
  • Loading branch information
skyclouds2001 authored Sep 29, 2024
1 parent 8bd9c4c commit 212f4a5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
12 changes: 8 additions & 4 deletions files/en-us/web/api/htmlanchorelement/port/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ browser-compat: api.HTMLAnchorElement.port

{{ApiRef("HTML DOM")}}

The **`HTMLAnchorElement.port`** property is a
string containing the port number of the URL. If the URL does not
contain an explicit port number, it will be set to `''`.
The **`port`** property of the {{domxref("HTMLAnchorElement")}} interface is a string containing the port number of the URL. If the URL does not contain an explicit port number or the port number is the same as the protocol's default, it will be `''`.

## Value

Expand All @@ -23,7 +21,13 @@ A string.
```js
// An <a id="myAnchor" href="https://developer.mozilla.org:443/en-US/docs/HTMLAnchorElement"> element is in the document
const anchor = document.getElementByID("myAnchor");
anchor.port; // returns '443'
anchor.port; // returns ''
```

```js
// Another <a id="myAnchor" href="https://developer.mozilla.org:8888/en-US/docs/HTMLAnchorElement"> element is in the document
const anchor = document.getElementByID("myAnchor");
anchor.port; // Returns:'8888'
```

## Specifications
Expand Down
12 changes: 8 additions & 4 deletions files/en-us/web/api/htmlareaelement/port/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ browser-compat: api.HTMLAreaElement.port

{{ApiRef("HTML DOM")}}

The **`HTMLAreaElement.port`** property is a
string containing the port number of the URL. If the URL does not
contain an explicit port number, it will be set to `''`.
The **`port`** property of the {{domxref("HTMLAreaElement")}} interface is a string containing the port number of the URL. If the URL does not contain an explicit port number or the port number is the same as the protocol's default, it will be `''`.

## Value

Expand All @@ -23,7 +21,13 @@ A string.
```js
// An <area id="myArea" href="https://developer.mozilla.org:443/en-US/docs/HTMLAreaElement"> element is in the document
const area = document.getElementByID("myArea");
area.port; // returns '443'
area.port; // Returns ''
```

```js
// Another <area id="myArea" href="https://developer.mozilla.org:8888/en-US/docs/HTMLAreaElement"> element is in the document
const area = document.getElementByID("myArea");
area.port; // Returns:'8888'
```

## Specifications
Expand Down
14 changes: 8 additions & 6 deletions files/en-us/web/api/location/port/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ browser-compat: api.Location.port

{{ApiRef("Location")}}

The **`port`** property of the {{domxref("Location")}}
interface is a string containing the port number of the URL. If the
URL does not contain an explicit port number, it will be set to `''`.
The **`port`** property of the {{domxref("Location")}} interface is a string containing the port number of the URL. If the URL does not contain an explicit port number or the port number is the same as the protocol's default, it will be `''`.

## Value

Expand All @@ -19,9 +17,13 @@ A string.
## Examples

```js
// Let's an <a id="myAnchor" href="https://developer.mozilla.org:443/en-US/docs/Location.port"> element be in the document
const anchor = document.getElementByID("myAnchor");
const result = anchor.port; // Returns:'443'
// 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'
```

## Specifications
Expand Down
3 changes: 1 addition & 2 deletions files/en-us/web/api/url/port/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ browser-compat: api.URL.port

{{ApiRef("URL API")}} {{AvailableInWorkers}}

The **`port`** property of the {{domxref("URL")}} interface is
a string containing the port number of the URL.
The **`port`** property of the {{domxref("URL")}} interface is a string containing the port number of the URL. If the URL does not contain an explicit port number or the port number is the same as the protocol's default, it will be `''`.

> [!NOTE]
> If an input string passed to the [`URL()`](/en-US/docs/Web/API/URL/URL) constructor doesn't contain an explicit port number (e.g., `https://localhost`) or contains a port number that's the default port number corresponding to the protocol part of the input string (e.g., `https://localhost:443`), then in the [`URL`](/en-US/docs/Web/API/URL) object the constructor returns, the value of the port property will be the empty string: `''`.
Expand Down

0 comments on commit 212f4a5

Please sign in to comment.