Html Notification Api Notifications

Date: 2018-10-23
<script>
    const requestNotifyPermission = (cb) => {
        if ('Notification' in window) {
            if (Notification.permission === 'granted') {
                setTimeout(cb, 0);
            }
            if (Notification.permission === 'default') {
                Notification.requestPermission().then((permission) => {
                    if (permission === 'granted') {
                        setTimeout(cb, 0);
                    }
                });
            }
        }
    };

    const showNotification = (title, text, opts) => {
        opts.body = text;
        let notification = new Notification(title, opts);
        notification.addEventListener('click', () => {
            parent.focus();
            window.focus(); //just in case, older browsers
            this.close();
        });
        setTimeout(notification.close.bind(notification), 5000);
    };

    window.addEventListener('load', () => {
        var imageUrl = "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
        requestNotifyPermission(() => {
            showNotification('This is the title', 'this is the bodY', {
                icon: imageUrl,
                //image: imageUrl,
                tag: 'this-tab'
            });
        });
    });
</script>

 

15370cookie-checkHtml Notification Api Notifications