📜 ⬆️ ⬇️

We send messages to Notification Center from the browser

With the release of Mac OSX 10.8, the Notification Center was introduced to users. As soon as you receive a new mail or message on Facebook, you will see a pop-up window in the upper right corner with a notification about it. Notification Center is identical to the notification bar in iOS.

Using the Notifications API, you can send notifications to the Mac OSX Mountain Lion Notification Center from the Safari browser.


Work with Notifications API was described in more detail by mythmaker on Habré in the topic habrahabr.ru/post/104670
')
I can supplement that article only by calling the window.webkitNotifications.requestPermission () method to take a callback function as a parameter.

window.webkitNotifications.requestPermission (function () {
// do something here ...
});

In Mac OS, up to version 10.8, JS Notification API was implemented in Google Chrome and worked just like other OSes. Since version 10.8, notification support has been added to Safari, but the display of the icon specified in the notification is not working. The icon of the application is displayed as the icon, from where the notice was called. It is also not possible to set HTML notifications.

The call code is very simple:
function shown(){ ( window.webkitNotifications.createNotification('message.png', ' !', ' . ...') ).show(); } 


Below are screenshots of the results of the script.

Call from Safari



Call from Google Chrome



And this was the notice in Google Chrome on Mac OSX in the previous version

Source: https://habr.com/ru/post/155039/


All Articles