Web聊天窗口提示框

收藏了一段Web聊天提示代碼,分享一下!!


<script type="text/javascript">

    function check() {
        // Let's check if the browser supports notifications
        if (!("Notification" in window)) {
            alert("This browser does not support desktop notification");
        }
        if (Notification.permission !== "granted") {
            Notification.requestPermission(function (permission) {
                // Whatever the user answers, we make sure we store the information
                if (!('permission' in Notification)) {
                    Notification.permission = permission;
                }
            });
        }
    }


    function notifyMe() {
        check();
        if (1 == 2) {
            var notification = new Notification("Hi there!");
        }
        else {
            var notification = new Notification('新的消息', {
                icon: 'https://developer.cdn.mozilla.net/static/img/opengraph-logo.dc4e08e2f6af.png',
                body: "Hey there! You've been notified!",
            });


            notification.onclick = function () {
                window.open("http://blog.csdn.net/liunianqingshi");
            };


        }
    }
</script>
發佈了29 篇原創文章 · 獲贊 43 · 訪問量 30萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章