如何使用 HTML5 的 Notification API

如题所述

document.getElementById('notifyButton').onclick
 = function ()
 {
    //检查浏览器是否支持Notification
    if (window.Notification){
        if(Notification.Permission==='granted'){
        //创建消息通知
            var notification
 = new Notification('Hello
 Notification',{body:"I
 hope that all the browser will support this\                   function!"});
            //展示消息通知
            notification.show();
        }else {
        //若权限不够则获取浏览器的通知权限
            document.getElementById('requestButton').onclick
 = function (){
                Notification.requestPermission();
            };
        };
    }else alert('你的浏览器不支持此特性,请下载谷歌浏览器试用该功能');
};

温馨提示:答案为网友推荐,仅供参考
相似回答