2011-03-22 108 views
6

我正在为我的网站开发一个谷歌浏览器扩展程序。谷歌通知上的点击事件

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

那么我该如何处理谷歌Chrome桌面通知点击事件?

+0

le baka tane point didho ... – asharajay 2012-10-05 09:12:45

回答

-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看作一个没有文本的完整链接。

+0

webkitNotifications.createHTMLNotification()不在API中。 – liwp 2013-01-09 13:59:09

+1

如果API已被弃用,答案是不是更新而不是投票呢? – user3163916 2014-08-09 07:48:22

4

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

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

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