单击链接时关闭html5 HTML通知

时间:2012-06-14 01:45:36

标签: html5 webkit google-chrome-extension notifications

我正在使用createHTMLNotification进行Chrome扩展。通知的html中包含一个链接。我想弄清楚的是如何在点击链接时关闭通知。我的代码正在关注

var notification = window.webkitNotifications.createHTMLNotification(
    "notification.html"
);
notification.show();

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

$('#title > a').click(function() {
    notification.cancel();
}

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

2 个答案:

答案 0 :(得分:5)

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

答案 1 :(得分:2)

您可以尝试以下方法将焦点设置为新打开的标签,并在途中关闭通知 notification.onclick = function(x) { window.focus(); this.cancel(); };

notification.show();

相关问题