2011-03-22 110 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();