点击Google通知上的活动

时间:2011-03-22 06:42:05

标签: google-chrome google-chrome-extension

我正在为我的网站开发一个谷歌浏览器扩展程序。

我希望当用户点击谷歌浏览器的桌面通知时,我的网站就会打开。

那么如何处理Google Chrome桌面通知点击事件?

2 个答案:

答案 0 :(得分:4)

如果您不想使用HTML通知,可以向通知添加点击事件处理程序并调用“取消”功能。

var notification = window.webkitNotifications.createNotification(
        'url', 'title', 'text');

notification.addEventListener('click', function() {
    notification.cancel();
    window.open('url')
})
notification.show();

答案 1 :(得分:-3)

基于此:http://code.google.com/chrome/extensions/notifications.html 我这样解决了:

我发了一个notification.html文件:

<html>
<head>
  <base target="_blank" />
</head>
<body>
  <a href="http://example.com">Open site</a>
</body>
</html>

我用这段代码打开通知:

var notification = webkitNotifications.createHTMLNotification(
    'notification.html'
);

notification.show();

您可以将CSS看起来像通知正文中没有文字的完整链接。