How about something like that?
var createNotificationWithLink = function(image, title, content, link) { var notification = window.webkitNotifications.createNotification(image, title, content); notification.onclose = function() { alert(':('); }; notification.onclick = function() { window.location.href = link; }; return notification; };
Now you can call createNotificationWithLink
whenever you want to create a notification:
var noti = createNotificationWithLink( 'http://funcook.com/img/favicon.png', 'HTML5 Notification', 'HTML5 Notification content...', 'http://mycustom.dynamic.link.com/' ); noti.show();
You can also move noti.show();
into the createNotificationWithLink
function if you want ( notification.show();
). I do not know if you want the notification to be automatically displayed when it is created ...
source share