I am developing a google chrom开发者_StackOverflow中文版e extension for my website.
I want that when the user clicks on the desktop notification of google chrome, that my website opens.
So how can I handle the google chrome desktop notification click event?
If you don't want to use an HTML notification, you can add a click event handler to the notification and call the "cancel" function.
var notification = window.webkitNotifications.createNotification(
'url', 'title', 'text');
notification.addEventListener('click', function() {
notification.cancel();
window.open('url')
})
notification.show();
Based on this: http://code.google.com/chrome/extensions/notifications.html I solved like this:
I made a notification.html file:
<html>
<head>
<base target="_blank" />
</head>
<body>
<a href="http://example.com">Open site</a>
</body>
</html>
And I open notification with this code:
var notification = webkitNotifications.createHTMLNotification(
'notification.html'
);
notification.show();
You can CSS the to look like a full link without text in notification body.
精彩评论