if (window.webkitNotifications) {
console.log( "Notifications are supported!" );
}
else {
console.log( "Notifications are not supported for this Browser/OS version yet." );
}
function createNotificationInstance(options) {
if (options.notificationType == 'simple' ) {
return window.webkitNotifications.createNotification(
'icon.png' , 'Notification Title' , 'Notification content...' );
} else if (options.notificationType == 'html' ) {
return window.webkitNotifications.createHTMLNotification( 'http://someurl.com' );
}
}
document .querySelector( '#show_button' ).addEventListener( 'click' , function () {
if (window.webkitNotifications.checkPermission() == 0) { // 0 is PERMISSION_ALLOWED
// function defined in step 2
createNotificationInstance({ notificationType: 'html' });
} else {
window.webkitNotifications.requestPermission();
}
}, false );
document .querySelector( '#show_button' ).addEventListener( 'click' , function () {
if (window.webkitNotifications.checkPermission() == 0) { // 0 is PERMISSION_ALLOWED
// function defined in step 2
notification_test = createNotificationInstance({notificationType: 'html' });
notification_test.ondisplay = function () { ... do something ... };
notification_test.onclose = function () { ... do something else ... };
notification_test.show();
} else {
window.webkitNotifications.requestPermission();
}
}, false );
Source: https://habr.com/ru/post/104670/