onmessage

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.

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

message 事件是在窗口接受到消息(例如,从另一个浏览器上下文中调用 Window.postMessage())时,在 Window 对象上触发的事件。

语法

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

规范

Specification
HTML
# event-message
HTML
# handler-window-onmessage

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
message event

Legend

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

Full support
Full support