{"id":1537,"date":"2018-10-23T13:52:36","date_gmt":"2018-10-23T12:52:36","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=1537"},"modified":"2018-10-23T13:52:36","modified_gmt":"2018-10-23T12:52:36","slug":"html-notification-api-notifications","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/html-notification-api-notifications\/","title":{"rendered":"Html Notification Api Notifications"},"content":{"rendered":"<pre class=\"lang:xhtml decode:true \">&lt;script&gt;\r\n    const requestNotifyPermission = (cb) =&gt; {\r\n        if ('Notification' in window) {\r\n            if (Notification.permission === 'granted') {\r\n                setTimeout(cb, 0);\r\n            }\r\n            if (Notification.permission === 'default') {\r\n                Notification.requestPermission().then((permission) =&gt; {\r\n                    if (permission === 'granted') {\r\n                        setTimeout(cb, 0);\r\n                    }\r\n                });\r\n            }\r\n        }\r\n    };\r\n\r\n    const showNotification = (title, text, opts) =&gt; {\r\n        opts.body = text;\r\n        let notification = new Notification(title, opts);\r\n        notification.addEventListener('click', () =&gt; {\r\n            parent.focus();\r\n            window.focus(); \/\/just in case, older browsers\r\n            this.close();\r\n        });\r\n        setTimeout(notification.close.bind(notification), 5000);\r\n    };\r\n\r\n    window.addEventListener('load', () =&gt; {\r\n        var imageUrl = \"data:image\/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o\/XBs\/fNwfjZ0frl3\/zy7\/\/\/\/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7\"\r\n        requestNotifyPermission(() =&gt; {\r\n            showNotification('This is the title', 'this is the bodY', {\r\n                icon: imageUrl,\r\n                \/\/image: imageUrl,\r\n                tag: 'this-tab'\r\n            });\r\n        });\r\n    });\r\n&lt;\/script&gt;\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&lt;script&gt; const requestNotifyPermission = (cb) =&gt; { if (&#8216;Notification&#8217; in window) { if (Notification.permission === &#8216;granted&#8217;) { setTimeout(cb, 0); } if (Notification.permission === &#8216;default&#8217;) { Notification.requestPermission().then((permission) =&gt; { if (permission === &#8216;granted&#8217;) { setTimeout(cb, 0); } }); } } }; const showNotification = (title, text, opts) =&gt; { opts.body = text; let notification = new [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1537","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/1537","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=1537"}],"version-history":[{"count":1,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/1537\/revisions"}],"predecessor-version":[{"id":1538,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/1537\/revisions\/1538"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=1537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=1537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=1537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}