Skip to content

Instantly share code, notes, and snippets.

@masckmaster2007
Created May 4, 2024 11:03
Show Gist options
  • Save masckmaster2007/78cb6238109fa05a8b831315edf7c8f3 to your computer and use it in GitHub Desktop.
Save masckmaster2007/78cb6238109fa05a8b831315edf7c8f3 to your computer and use it in GitHub Desktop.
Notification API Example
Notification.requestPermission().then(permission => {
if(permission !== "granted") return; // User refused notifications
const image = "https://dgdps.ix.tc/gd.png"; // Logo for notification
const target = "https://dgdps.us.to"; // Website to open if user clicks on it
const title = "Test"; // Notification title
const msg = "Salut"; // Notification body message
const notify = new Notification(title, { body: msg, icon: image }); // Builds notification
notify.onclick = function () {
window.open(target); // Open site
notify.close(); // Closes notification (x)
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment