javascript to pop browser notification

Solutions on MaxInterview for javascript to pop browser notification by the best coders in the world

showing results for - "javascript to pop browser notification"
Elisa
24 Mar 2017
1<!doctype html>
2	<head>
3		<title>Show Notification using Javascript</title>
4	</head>
5	<body>
6		<h3>Show Notification using Javascript</h3>
7
8
9      <script>
10      /* JS comes here */
11      askForApproval();
12
13      function askForApproval() {
14        if(Notification.permission === "granted") {
15          createNotification('Wow! This is great', 
16                             'created by @study.tonight', 
17                             'https://www.studytonight.com/css/resource.v2/icons/studytonight/st-icon-dark.png');
18        }
19        else {
20          Notification.requestPermission(permission => {
21            if(permission === 'granted') {
22              createNotification('Wow! This is great', 'created by @study.tonight', 'https://www.studytonight.com/css/resource.v2/icons/studytonight/st-icon-dark.png');
23            }
24          });
25        }
26      }
27
28      function createNotification(title, text, icon) {
29        const noti = new Notification(title, {
30          body: text,
31          icon
32        });
33      }
34      </script>
35	</body>
36</html>