Notifications 编辑

Notifications allow you to communicate information about your extension or its content using the underlying operating system's notification service.

Notifications can include a call to action for the user, and your add-on can listen for the user clicking the notification or the notification closing.

Specifying notifications

You manage notifications programmatically, using the notifications API. To use this API you must request the notifications permission in your manifest.json:

"permissions": ["notifications"]

You then use notifications.create to create your notifications, as in this example from notify-link-clicks-i18n:

var title = browser.i18n.getMessage("notificationTitle");
var content = browser.i18n.getMessage("notificationContent", message.url);
browser.notifications.create({
  "type": "basic",
  "iconUrl": browser.extension.getURL("icons/link-48.png"),
  "title": title,
  "message": content
});

This code creates a notification with an icon, title, and message.

If the notification includes a call to action, you can listen for the user clicking the notification to call the function to handle the action:

browser.notifications.onClicked.addListener(handleClick);

If you are issuing calls to action through notifications, you will also want to define the optional notification id, so you can figure out which call to action the user has selected.

Icons

For details on how to create icons to use with your notification, see Iconography in the Photon Design System documentation.

Examples

The webextensions-examples repository on GitHub includes the notify-link-clicks-i18n example which implements notifications.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:135 次

字数:2944

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文