Created
September 26, 2017 11:58
-
-
Save momin-riyadh/a14e480ec859cd3c0875f675cdb31840 to your computer and use it in GitHub Desktop.
JavaScript notification popup
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>JavaScript Notification</title> | |
| </head> | |
| <body> | |
| <script type="text/javascript"> | |
| function notifyMe() { | |
| if (!("Notification" in window)) { | |
| alert("This browser does not support system notifications"); | |
| } else if (Notification.permission === "granted") { | |
| notify(); | |
| } else if (Notification.permission !== 'denied') { | |
| Notification.requestPermission(function(permission) { | |
| if (permission === "granted") { | |
| notify(); | |
| } | |
| }); | |
| } | |
| function notify() { | |
| var notification = new Notification('UScraft LLC', { | |
| icon: 'https://unsplash.it/400/400?random', | |
| body: "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda accusamus nesciunt excepturi, doloribus porro, sequi.", | |
| }); | |
| notification.onclick = function() { | |
| window.open("https:google.com"); | |
| }; | |
| setTimeout(notification.close.bind(notification), 7000); | |
| } | |
| } | |
| notifyMe(); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment