Created
May 4, 2016 13:06
-
-
Save anonymous/c3cfa3e4e68d03d44a71d27160576912 to your computer and use it in GitHub Desktop.
// source https://jsbin.com/ziwod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <button onclick="notifyMe()"> | |
| Notify me! | |
| </button> | |
| <script id="jsbin-javascript"> | |
| // request permission on page load | |
| document.addEventListener('DOMContentLoaded', function () { | |
| if (Notification.permission !== "granted") | |
| Notification.requestPermission(); | |
| }); | |
| function notifyMe() { | |
| if (!Notification) { | |
| alert('Desktop notifications not available in your browser. Try Chromium.'); | |
| return; | |
| } | |
| if (Notification.permission !== "granted") | |
| Notification.requestPermission(); | |
| else { | |
| var notification = new Notification('Notification title', { | |
| icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png', | |
| body: "Hey there! You've been notified!", | |
| }); | |
| notification.onclick = function () { | |
| window.open("http://stackoverflow.com/a/13328397/1269037"); | |
| }; | |
| } | |
| } | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript">// request permission on page load | |
| document.addEventListener('DOMContentLoaded', function () { | |
| if (Notification.permission !== "granted") | |
| Notification.requestPermission(); | |
| }); | |
| function notifyMe() { | |
| if (!Notification) { | |
| alert('Desktop notifications not available in your browser. Try Chromium.'); | |
| return; | |
| } | |
| if (Notification.permission !== "granted") | |
| Notification.requestPermission(); | |
| else { | |
| var notification = new Notification('Notification title', { | |
| icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png', | |
| body: "Hey there! You've been notified!", | |
| }); | |
| notification.onclick = function () { | |
| window.open("http://stackoverflow.com/a/13328397/1269037"); | |
| }; | |
| } | |
| } | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // request permission on page load | |
| document.addEventListener('DOMContentLoaded', function () { | |
| if (Notification.permission !== "granted") | |
| Notification.requestPermission(); | |
| }); | |
| function notifyMe() { | |
| if (!Notification) { | |
| alert('Desktop notifications not available in your browser. Try Chromium.'); | |
| return; | |
| } | |
| if (Notification.permission !== "granted") | |
| Notification.requestPermission(); | |
| else { | |
| var notification = new Notification('Notification title', { | |
| icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png', | |
| body: "Hey there! You've been notified!", | |
| }); | |
| notification.onclick = function () { | |
| window.open("http://stackoverflow.com/a/13328397/1269037"); | |
| }; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment