单击链接时关闭html5 HTMLNotification

bre*_*rer 1 html5 notifications webkit google-chrome-extension

我正在使用createHTMLNotificationChrome扩展程序.通知的html中包含一个链接.我想弄清楚的是如何在点击链接时关闭通知.我的代码如下

var notification = window.webkitNotifications.createHTMLNotification(
    "notification.html"
);
notification.show();
Run Code Online (Sandbox Code Playgroud)

notification.html页面上的代码填写了数据.该页面包含jquery库.当我尝试做的时候:

$('#title > a').click(function() {
    notification.cancel();
}
Run Code Online (Sandbox Code Playgroud)

这当然不起作用,因为在这个html页面上通知是未知的.我还尝试notification.onshow在代码的第一部分中创建通知,但是这也没有产生任何结果.

bre*_*rer 5

好吧我明白了.这实际上是一个非常简单的修复.您只需在通知中的href的click事件中添加即可window.close().这是因为根据W3C规范,它是一个单独的窗口,因此您可以这样处理它