aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/broadcastchannel/messageerror_event
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/broadcastchannel/messageerror_event
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/broadcastchannel/messageerror_event')
-rw-r--r--files/zh-cn/web/api/broadcastchannel/messageerror_event/index.html83
1 files changed, 83 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/broadcastchannel/messageerror_event/index.html b/files/zh-cn/web/api/broadcastchannel/messageerror_event/index.html
new file mode 100644
index 0000000000..22b1a722f2
--- /dev/null
+++ b/files/zh-cn/web/api/broadcastchannel/messageerror_event/index.html
@@ -0,0 +1,83 @@
+---
+title: 'BroadcastChannel: messageerror event'
+slug: Web/API/BroadcastChannel/messageerror_event
+translation_of: Web/API/BroadcastChannel/messageerror_event
+---
+<div>{{APIRef}}</div>
+
+<p>当频道收到一条无法反序列化的消息时会在 {{domxref('BroadcastChannel')}} 对象上触发 <code>messageerror</code> 事件。</p>
+
+<table class="properties">
+ <tbody>
+ <tr>
+ <th scope="row">Bubbles</th>
+ <td>No</td>
+ </tr>
+ <tr>
+ <th scope="row">Cancelable</th>
+ <td>No</td>
+ </tr>
+ <tr>
+ <th scope="row">Interface</th>
+ <td>{{domxref("MessageEvent")}}</td>
+ </tr>
+ <tr>
+ <th scope="row">Event handler property</th>
+ <td><code><a href="/en-US/docs/Web/API/BroadcastChannel/onmessageerror">onmessageerror</a></code></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="示例">示例</h2>
+
+<p>以下代码使用 <code><a href="/en-US/docs/Web/API/EventTarget/addEventListener">addEventListener</a></code> 来监听消息和错误:</p>
+
+<pre class="brush: js">const channel = new BroadcastChannel('example-channel');
+
+channel.addEventListener('message', (event) =&gt; {
+ received.textContent = event.data;
+});
+
+channel.addEventListener('messageerror', (event) =&gt; {
+ console.error(event);
+});</pre>
+
+<p>使用 <code><a href="/en-US/docs/Web/API/BroadcastChannel/onmessage">onmessage</a></code> 和 <code><a href="/en-US/docs/Web/API/BroadcastChannel/onmessageerror">onmessageerror</a></code> 事件处理程序来实现相同效果:</p>
+
+<pre class="brush: js">const channel = new BroadcastChannel('example-channel');
+
+channel.onmessage = (event) =&gt; {
+ received.textContent = event.data;
+};
+
+channel.onmessageerror = (event) =&gt; {
+ console.log(event);
+};
+</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">规范</th>
+ <th scope="col">状态</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML WHATWG', 'indices.html#event-messageerror')}}</td>
+ <td>{{Spec2('HTML WHATWG')}}</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("api.BroadcastChannel.messageerror_event")}}</p>
+
+<h2 id="另见">另见</h2>
+
+<ul>
+ <li>相关事件:<code><a href="/docs/Web/API/BroadcastChannel/message_event">message</a></code></li>
+</ul>