push notification javascript code example
Example 1: javascript to push browser notification
<!doctype html>
<head>
<title>Show Notification using Javascript</title>
</head>
<body>
<h3>Show Notification using Javascript</h3>
<script>
askForApproval();
function askForApproval() {
if(Notification.permission === "granted") {
createNotification('Wow! This is great',
'created by @study.tonight',
'https://www.studytonight.com/css/resource.v2/icons/studytonight/st-icon-dark.png');
}
else {
Notification.requestPermission(permission => {
if(permission === 'granted') {
createNotification('Wow! This is great', 'created by @study.tonight', 'https://www.studytonight.com/css/resource.v2/icons/studytonight/st-icon-dark.png');
}
});
}
}
function createNotification(title, text, icon) {
const noti = new Notification(title, {
body: text,
icon
});
}
</script>
</body>
</html>
Example 2: data submit notification in javascript
<script src="http://www.jqueryscript.net/demo/Sliding-Growl-Notification-Plugin-For-jQuery-jsnotify/dist/js/notify.js"></script>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<link href="http://www.jqueryscript.net/demo/Sliding-Growl-Notification-Plugin-For-jQuery-jsnotify/dist/css/notify.css" rel="stylesheet"/>
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" rel="stylesheet"/>
<form action="" method="post" id="myDiv">
<input type="text" name="name" id="n1">
<input type="text" name="mobile" id="n2">
<input type="submit" name="submit" value="click me">
</form>