Thursday, August 11, 2016

Browser Notification


<!DOCTYPE html>
<html>
<head>
<title>Dharamart.blogspot.com</title>
<script type="text/javascript">

var articles = [
["dharamart.blogspot.com"],
["dharamart.blogspot1"],
["dharamart.blogspot2"]
];


setTimeout(function(){
var x = Math.floor((Math.random() * 3) + 1);
var title=articles[x][0];
var desc='dharamart.blogspot.com';
var url=articles[x][1];
notifyBrowser(title,desc,url);
}, 200000);



document.addEventListener('DOMContentLoaded', function ()
{
 
if (Notification.permission !== "granted")
{
Notification.requestPermission();
}

$( document ).ready(function() {
var x = Math.floor((Math.random() * 10) + 1);
var title=articles[x][0];
var desc='www.veggies24x7.com.';
var url=articles[x][1];
notifyBrowser(title,desc,url);
e.preventDefault();
});

});

function notifyBrowser(title,desc,url)
{
if (!Notification) {
console.log('Desktop notifications not available in your browser..');
return;
}
if (Notification.permission !== "granted")
{
Notification.requestPermission();
}
else {
var notification = new Notification(title, {
icon:'https://dharamart.blogspot.in/favicon.ico',
body: desc,
});

// Remove the notification from Notification Center when clicked.
notification.onclick = function () {
window.open(url);    
};

// Callback function when the notification is closed.
notification.onclose = function () {
console.log('Notification closed');
};

}
}


</script>
</head>
<body>

<a href="#"  id="notificationButton" class="button">Notification</a>



</body>
</html>

No comments:

Post a Comment

Dharamart.blogspot.in