Skip to content

Instantly share code, notes, and snippets.

@momin-riyadh
Created September 26, 2017 11:58
Show Gist options
  • Select an option

  • Save momin-riyadh/a14e480ec859cd3c0875f675cdb31840 to your computer and use it in GitHub Desktop.

Select an option

Save momin-riyadh/a14e480ec859cd3c0875f675cdb31840 to your computer and use it in GitHub Desktop.
JavaScript notification popup
<!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