Desktop Notifications

Developer
Size
1,975 Kb
Views
6,072

How do I make an desktop notifications?

Demo of desktop notices for FF and Chrome.... What is a desktop notifications? How do you make a desktop notifications? This script and codes were developed by Jeff Daze on 18 January 2023, Wednesday.

Desktop Notifications Previews

Desktop Notifications - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Desktop Notifications</title>
</head>
<body> <button id="launch">Launch Notification</button>
<div id="log"></div> <script src="js/index.js"></script>
</body>
</html>

Desktop Notifications - Script Codes JS Codes

//vars...
var log = document.getElementById('log');
var notificationEvents = ['onclick', 'onshow', 'onerror', 'onclose'];
function notifyUser(event) { var title; var options; //event.preventDefault(); title = 'Email received'; title = "Some User <[email protected]>"; options = { body: 'You have a total of '+getRandomInt(2, 10)+' unread emails', tag: 'preset', icon: 'http://jeffdaze.com/favicon.ico' }; Notification.requestPermission(function() { var notification = new Notification(title, options); notificationEvents.forEach(function(eventName) { notification[eventName] = function(event) { log.innerHTML = 'Event "' + event.type + '" triggered for notification "' + notification.tag + '"<br />' + log.innerHTML; }; }); }); }
function notifyUser2() { console.log("notice fired..."); var title; var options; //event.preventDefault(); title = 'Email received'; options = { body: 'You have a total of '+getRandomInt(2, 10)+' unread emails', tag: 'preset', icon: 'http://jeffdaze.com/favicon.ico' }; Notification.requestPermission(function() { var notification = new Notification(title, options); }); }
setTimeout(notifyUser2, 500);
setTimeout(notifyUser2, 1000);
setTimeout(notifyUser2, 1500);
setTimeout(notifyUser2, 2000);
setTimeout(notifyUser2, 10000);
//bind click to button...
document.getElementById('launch').addEventListener('click', notifyUser);
function getRandomInt(min, max){ return Math.floor(Math.random() * (max - min + 1)) + min;
}
Desktop Notifications - Script Codes
Desktop Notifications - Script Codes
Home Page Home
Developer Jeff Daze
Username jeffdaze
Uploaded January 18, 2023
Rating 3
Size 1,975 Kb
Views 6,072
Do you need developer help for Desktop Notifications?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Jeff Daze (jeffdaze) Script Codes
Create amazing blog posts with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!