--- title: onmessage slug: Web/API/WindowEventHandlers/onmessage translation_of: Web/API/WindowEventHandlers/onmessage ---

{{APIRef("HTML DOM")}}{{ SeeCompatTable() }}

{{domxref("WindowEventHandlers")}}的onmessage 属性是当对象接收到{{event("message")}} 事件时被调用的{{domxref("EventHandler")}} .

语法

window.addEventListener('message', function(event) { ... })
window.onmessage = function(event) { ... }

规范

Specification Status Comment
{{SpecName('HTML WHATWG','#handler-window-onmessage','onmessage')}} {{Spec2('HTML WHATWG')}} Initial definition.

浏览器兼容性

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatChrome(60)}} {{CompatUnknown}} {{CompatUnknown}} {{CompatOpera(47)}} {{CompatUnknown}}
Feature Android Webview Chrome for Android Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatChrome(60)}} {{CompatChrome(60)}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatOperaMobile(47)}} {{CompatUnknown}}