Comment: This article mainly introduces the usage of HTML5 Notification (desktop reminder) function, and uses examples to illustrate the effect of desktop reminder. Friends who need it can refer to it.
1. Introduction to HTML5 Notification
HTML5 Notification, that is, desktop notifications. At present, the browser is still a strict sandbox working mode, which isolates the communication between the browser and the desktop. Notification can cross sandboxes to allow browsers to notify users of messages even if they minimize state.
2. Desktop Reminder API
There are 3 methods for this API:
checkPermission Check desktop notification permission (PERMISSION_ALLOWED = 0, PERMISSION_NOT_ALLOWED = 1, PERMISSION_DENIED = 2)
createNotification Create desktop notifications
3. Desktop notification example
Let's use the desktop notification API to write a small function: send a message on the desktop every 20 minutes to remind users to take a break.
The code is as follows:
if(window.webkitNotifications.checkPermission()==0){
setInterval(function(){
var popup = window.webkitNotifications.createNotification("avator.jpg","Ruhua warm reminder: ","You will blind your eyes when facing the computer for a long time, take a break~!");
popup.show();
},1000 * 60 * 20);</p><p> }else{
window.webkitNotifications.requestPermission();
}
}else{
alert('The browser does not support desktop notifications ~!');
}
Then 20 minutes later the desktop will appear: