当前位置: 代码迷 >> Web前端 >> 开发指南-浏览器用户界面-圆桌面通知(Desktop Notifications)
  详细解决方案

开发指南-浏览器用户界面-圆桌面通知(Desktop Notifications)

热度:505   发布时间:2012-10-26 10:30:58.0
开发指南--浏览器用户界面--桌面通知(Desktop Notifications)
桌面通知(Desktop Notifications)
可以使用桌面通知来通知用户一些重要的信息。通知在浏览器窗口外显示。就像截图表示的一样,通知的外观取决于它所运行于的平台。
原文 写道
Use desktop notifications to notify users that something important has happened. Notifications appear outside the browser window. As the following snapshots show, the details of how notifications look and where they're shown depend on the platform.





你可以通过JavaScript或者一个HTML文件创建一个通知窗口。
原文 写道
You create the notification window using a bit of JavaScript and, optionally, an HTML page packaged inside your extension.

Manifest
你可以在manifest文件中request请求一个通知的权限,如下:
原文 写道
You can request the notification permission in the extension manifest, like this:

{
  "name": "My extension",
  ...
  "permissions": [
    "notifications"
  ],
  ...
}

注意:在创建通知的时候扩展工具始终允许声明通知权限。所以不需要调用webkitNotifications.checkPermission()
原文 写道
Note: Extensions that declare the notifications permission are always allowed to create notifications. There is no need to call webkitNotifications.checkPermission().

API
桌面通知API同样也支持使用一个标准的网页。根据下面的代码,你可以创建一个文本的通知或者HTML的通知,然后显示它。
原文 写道
The desktop notification API for extensions is the same one that is available to normal web pages. As the following code shows, you first create either a simple text notification or an HTML notification, and then you show the notification.

// 创建一个文本通知:
var notification = webkitNotifications.createNotification(
  '48.png',  // 图标路径 - 可以是相对路径
  'Hello!',  // 通知的标题
  'Lorem ipsum...'  // 通知的内容
);

// 或者创建一个HTML通知:
var notification = webkitNotifications.createHTMLNotification(
  'notification.html'  // HTML路径 - 可以是相对路径
);

// 然后显示通知.
notification.show();

API的详细信息,请参照Desktop notifications draft specification.
原文 写道
For complete API details, see the Desktop notifications draft specification.
  相关解决方案