push event is sent to a service worker's global scope (represented by the ServiceWorkerGlobalScope interface) when the service worker has received a push message.

冒泡 No
可取消 No
接口 PushEvent
事件处理程序特性 onpush

范例

This example sets up a handler for push events that takes JSON data, parses it, and dispatches the message for handling based on information contained within the message.

self.addEventListener("push", event => {
  let message = event.data.json();
  switch(message.type) {
    case "init":
      doInit();
      break;
    case "shutdown":
      doShutdown();
      break;
  }
}, false);
					

规范

规范 状态 注释
Push API
The definition of 'push' in that specification.
工作草案 最初的规范。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
push event Chrome 40 Edge ≤79 Firefox 44
44
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE No Opera 24 Safari 11.1 WebView Android 40 Chrome Android 40 Firefox Android 44 Opera Android 24 Safari iOS 11.3 Samsung Internet Android 4.0

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

另请参阅

元数据

  • 最后修改: