The Wayback Machine - https://web.archive.org/web/20150910081641/https://developer.mozilla.org/zh-CN/docs/Web/API/PushMessageData

PushMessageData

3 位贡献者:
我们的志愿者还没有将这篇文章翻译为 中文 (简体) 。加入我们帮助完成翻译!

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the spec changes.

The PushMessageData interface of the Push API provides access to push data sent by a server, and methods to manipulate the data.

Properties

None

Methods

PushMessageData.arrayBuffer()
Extracts the data as an ArrayBuffer object.
PushMessageData.blob()
Extracts the data as a Blob object.
PushMessageData.json()
Extracts the data as a JSON object.
PushMessageData.text()
Extracts the data as a plain text string.

Examples

self.addEventListener('push', function(event) {
  if (!(self.Notification && self.notification.permission === 'granted')) {
    return;
  }

  var data = {};
  if (event.data) {
    data = event.data.json();
  }
  var title = data.title || "Something Has Happened";
  var message = data.message || "Here's something you might want to check out.";
  var icon = "images/new-notification.png";

  var notification = new Notification(title, {
    body: message,
    tag: 'simple-push-demo-notification',
    icon: icon
  });

  notification.addEventListener('click', function() {
    if (clients.openWindow) {
      clients.openWindow('https://example.blog.com/2015/03/04/something-new.html');
    }
  };
});

Specifications

Specification Status Comment
Push API
The definition of 'PushMessageData' in that specification.
Working Draft Initial definition.

Browser Compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support Not supported Not supported Not supported Not supported Not supported
Feature Android Android Webview Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support Not supported Not supported Not supported Not supported Not supported Not supported Not supported Not supported

See also

文档标签和贡献者

向此页面作出贡献: chrisdavidmills, jpmedley, nyrosmith
最后编辑者: chrisdavidmills,