欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

HTML5實(shí)現(xiàn)桌面通知 提示功能

  發(fā)布時(shí)間:2017-10-11 15:52:46   作者:佚名   我要評(píng)論
這篇文章主要介紹了HTML5實(shí)現(xiàn)桌面通知 提示功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧

具體代碼如下所示:

<button id="button">有人想加你為好友</button>
<p id="text"></p>
;(function (){
    if(window.Notification){
        var btn = document.getElementById("button");
        var txt = document.getElementById("text");
        btn.onclick = function (){
            if(Notification.permission == "granted"){
                popNotice();
            }else if(Notification.permission != "denied"){
                Notification.requestPermission().then(function (permission){
                    popNotice()
                })
            }
        };
        function popNotice(){
            if(Notification.permission == "granted"){
                var notification = new Notification("你好:",{
                    body:"請(qǐng)問(wèn)今晚有空嗎",
                    icon:"http://image.zhangxinxu.com/左邊頭像地址"
                });
                notification.onclick = function (){
                    txt.innerHTML = new Date().toTimeString().split(" ")[0]+"收到信息";
                    notification.close();
                }
            }
        }
    }else{
        console.log("瀏覽器不支持Notification");
    }
})();

Notification.requestPermission()是個(gè)請(qǐng)求 ,讓瀏覽器出現(xiàn)是否允許通知的提示 和 Notification.permission 一樣 返回 "3"個(gè)值 "granted" "default" "denied" 戶(hù)允許通知, 用戶(hù)目前還沒(méi)有管, 用戶(hù)嫌棄

總結(jié)

以上所述是小編給大家介紹的HTML5實(shí)現(xiàn)桌面通知 提示功能,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論