[size=x-large][b]桌面通知(Desktop Notifications)[/b][/size]
可以使用桌面通知来通知用户一些重要的信息。通知在浏览器窗口外显示。就像截图表示的一样,通知的外观取决于它所运行于的平台。
[quote="原文"]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.[/quote]
[img]http://code.google.com/chrome/extensions/images/notification-windows.png[/img]
[img]http://code.google.com/chrome/extensions/images/notification-mac.png[/img]
[img]http://code.google.com/chrome/extensions/images/notification-linux.png[/img]
你可以通过JavaScript或者一个HTML文件创建一个通知窗口。
[quote="原文"]You create the notification window using a bit of JavaScript and, optionally, an HTML page packaged inside your extension.[/quote]
[color=green][b][size=large]Manifest[/size][/b][/color]
你可以在manifest文件中request请求一个通知的权限,如下:
[quote="原文"]You can request the notification permission in the extension manifest, like this:[/quote]
[b]注意:[/b]在创建通知的时候扩展工具始终允许声明[color=green]通知[/color]权限。所以不需要调用[color=green]webkitNotifications.checkPermission()[/color]。
[quote="原文"]Note: Extensions that declare the notifications permission are always allowed to create notifications. There is no need to call webkitNotifications.checkPermission().[/quote]
[color=green][b][size=large]API[/size][/b][/color]
桌面通知API同样也支持使用一个标准的网页。根据下面的代码,你可以创建一个文本的通知或者HTML的通知,然后显示它。
[quote="原文"]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.[/quote]
API的详细信息,请参照[url=http://dev.chromium.org/developers/design-documents/desktop-notifications/api-specification]Desktop notifications draft specification.[/url]
[quote="原文"]For complete API details, see the Desktop notifications draft specification.[/quote]
可以使用桌面通知来通知用户一些重要的信息。通知在浏览器窗口外显示。就像截图表示的一样,通知的外观取决于它所运行于的平台。
[quote="原文"]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.[/quote]
[img]http://code.google.com/chrome/extensions/images/notification-windows.png[/img]
[img]http://code.google.com/chrome/extensions/images/notification-mac.png[/img]
[img]http://code.google.com/chrome/extensions/images/notification-linux.png[/img]
你可以通过JavaScript或者一个HTML文件创建一个通知窗口。
[quote="原文"]You create the notification window using a bit of JavaScript and, optionally, an HTML page packaged inside your extension.[/quote]
[color=green][b][size=large]Manifest[/size][/b][/color]
你可以在manifest文件中request请求一个通知的权限,如下:
[quote="原文"]You can request the notification permission in the extension manifest, like this:[/quote]
{
"name": "My extension",
...
"permissions": [
"notifications"
],
...
}
[b]注意:[/b]在创建通知的时候扩展工具始终允许声明[color=green]通知[/color]权限。所以不需要调用[color=green]webkitNotifications.checkPermission()[/color]。
[quote="原文"]Note: Extensions that declare the notifications permission are always allowed to create notifications. There is no need to call webkitNotifications.checkPermission().[/quote]
[color=green][b][size=large]API[/size][/b][/color]
桌面通知API同样也支持使用一个标准的网页。根据下面的代码,你可以创建一个文本的通知或者HTML的通知,然后显示它。
[quote="原文"]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.[/quote]
// 创建一个文本通知:
var notification = webkitNotifications.createNotification(
'48.png', // 图标路径 - 可以是相对路径
'Hello!', // 通知的标题
'Lorem ipsum...' // 通知的内容
);
// 或者创建一个HTML通知:
var notification = webkitNotifications.createHTMLNotification(
'notification.html' // HTML路径 - 可以是相对路径
);
// 然后显示通知.
notification.show();
API的详细信息,请参照[url=http://dev.chromium.org/developers/design-documents/desktop-notifications/api-specification]Desktop notifications draft specification.[/url]
[quote="原文"]For complete API details, see the Desktop notifications draft specification.[/quote]