Today’s browsers give easy to set custom push notifications, it’s possible on latest browsers and got easy way to set you website or blog. Very few line of JavaScript code, that can help you to interact with browser notification system.
Demo
Below small code for execute push notification:
<script language=”javascript”>
showNotification(“Welcome to 9code.info”,”Just updated new article”,”https://9code.info/”);
function showNotification(title,desc,url)
{
if (Notification.permission !== “granted”)
{
Notification.requestPermission();
}
else
{
var notification = new Notification(title, {
icon:’https://9code.info//wp-content/themes/genesis/images/logo.png’,
body: desc,
});
notification.onclick = function () {
window.open(url,”_blank”);
};
/* Callback function when the notification is closed. */
notification.onclose = function () {
alert(‘Notification closed’);
};
}
}</script>
Note: Push notification not supported older browser
Leave a Reply