ajax polling with Windows notification system

Project needs, make B / S project packaged into exe executable file, and minimize to the bottom right of the taskbar, news time notification alerts

Javaweb project packed with Nativefier interested students can understand their own Baidu, I was halfway decent, not very familiar with this stuff, and good packaging completed

The code is as follows, we are interested can own in-depth study

<Script type = "text / JavaScript"> 
var DATAl = "OA alert";
var DATA2 = "You have new messages";


var SendMessage = {
URL: '/ reminderManage',
dataType: 'JSON',
Success: function ( data) {
IF (data.msg == "OK") {
showNotice (DATAl, DATA2);
}
}
};
// Ajax regular access server, continuous access to data.
the window.setInterval (function () {$ Ajax (SendMessage).}, 5000);



// the setInterval ( "showNotice (DATAl, DATA2)", 50000);
var = window.Notification the Notification ||
window.mozNotification ||
window. webkitNotification;

// var = new new Media Audio ( "HTTP: //****.mp3");

showNotice function (title, msg) {
IF (the Notification) {
Notification.requestPermission (function (Status) {
// Status defaults 'default' is equivalent to denial 'denied' means that the user does not want to notice 'granted' means that users agree to enable notification
IF (! "granted" Status =) {
return;
} the else {
var Tag = "Order" + Math.random (); // generate random tag, when clicked convenient location processing
console.log ( "tag:" + Tag)
var = new new Notify the notification (
title,
{
Tag: Tag,
// icon: 'HTTP: thumbnail //******.png',// notification, // icon support ico, png, jpg , jpeg format
icon: 'http://127.0.0.1:8088/images/title.png',
body: specific content of the notification msg //
}
);
notify.onclick = function () {
// if the notification message is clicked, the notification window will be activated
// media.pause ();
the window.focus ();
notify.close ();
};
notify.onerror = function () {
the console.log ( "error message the HTML5 Desktop !!!");
};
notify.onshow = function () {
// Media.play ();

// after 5S self-stop notification
the setTimeout (function () {
notify.close ();
// media.pause ();
}, 5000);
}
};
notify.onclose = function () {
the console.log ( "desktop messaging off the HTML5 !!!");
// media.pause ();
};
});
} {the else
the console.log ( "your browser does not support desktop message");
}
};
</ Script>

Guess you like

Origin www.cnblogs.com/michaelcnblogs/p/12132373.html
Recommended