B
B
Bogdan Pasechnik2012-07-02 12:04:35
JavaScript
Bogdan Pasechnik, 2012-07-02 12:04:35

How does VKontakte display a message when the tab is not active?

When a message arrives on vk.com, even if I'm reading Habr right now, a message pops up at the bottom right.
I wanted to know how they did it.




Decision



            if (typeof window.webkitNotifications == 'undefined') {
                console.log('Notifications API не поддерживается вашим браузером.');
            } else {
                if (webkitNotifications.checkPermission() != 0) {
                    webkitNotifications.requestPermission();
                }
                var notification=webkitNotifications.createNotification('icon.png', 'Заголовок', 'Проверка Notifications API');
                notification.show();
            }

It is important that the requestPermission method be called on a user event. Otherwise, chrome will block its execution for security purposes.
Read here y3x.ru/2011/02/js-web-notifications-api/

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mikhail Osher, 2012-07-02
@taral

It's a fun thing - notifications in Google Chrome.
support.google.com/mail/bin/answer.py?hl=ru&answer=1075549
And on/off - vk.com/im At the
bottom there is "Enable / Disable Notifications"

S
Sergey, 2012-07-02
Protko @Fesor

I've never seen anything like this, are you sure it's JS and not a browser add-on?

V
Vlad Zhivotnev, 2012-07-02
@inkvizitor68sl

Just like gmail =)
But the contact itself doesn’t seem to know how, it’s more like an add-on (MusicSig?)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question