window.Notification implements desktop notifications

var popNotice = function() {
        if (Notification.permission == "granted") {
            var notification = new Notification("Hi,", {
                body: 'Can I add you as a friend? ',
                icon: '/static/cute.gif'
            });
            
            notification.onclick = function() {
                alert('*** has added you as a friend at ' + new Date().toTimeString().split(' ')[0] + '!');
                notification.close();    
            };
        }    
    };

    if (window.Notification) {
        if (Notification.permission == "granted") {
            popNotice ();
        }else if( Notification.permission != "denied"){
            Notification.requestPermission(function (permission) {
              popNotice ();
            });
        }
    } else {
        alert('The browser does not support Notification');    
    }


The reference address for this article: http://www.zhangxinxu.com/wordpress/?p=5474

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325690878&siteId=291194637