-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.md
56 lines (35 loc) · 1.14 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
title: MessagePort.close()
slug: Web/API/MessagePort/close
---
{{APIRef("HTML DOM")}}
{{domxref("MessagePort")}} インターフェイスの **`close()`** メソッドは、ポートの接続を切断し、ポートがアクティブではなくなります。これは、そのポートへのメッセージの送信を停止します。
{{AvailableInWorkers}}
## 構文
```
port.close()
```
### 戻り値
無効。
### 引数
なし。
## 例
次のコードブロックには、`handleMessage` ハンドラ関数があり、{{domxref("EventTarget.addEventListener")}} を使用してこのドキュメントにメッセージが返された時に実行されます。
```js
channel.port1.addEventListener("message", handleMessage, false);
function handleMessage(e) {
para.innerHTML = e.data;
textInput.value = "";
}
channel.port1.start();
```
次のようにして、いつでもメッセージの送信を停止できます。
```js
channel.port1.close();
```
## 仕様
{{Specifications}}
## ブラウザの実装状況
{{Compat}}
## 関連情報
- [Using channel messaging](/ja/docs/Web/API/Channel_Messaging_API/Using_channel_messaging)