Comments: This article describes how to use the HTML5 Notification (desktop Reminder) function. You can use instances to describe the desktop reminder effect. For more information, see
1. Introduction to HTML5 Notification
HTML5 Notification, that is, desktop Notification. The browser is still a strict sandbox working mode, which isolates the communication between the browser and the desktop. Notification can span the sandbox so that the browser can send messages to users even if they are in a minimized state.
Ii. Desktop reminder API
The Code is as follows: window. webkitNotifications
This API has three methods:
The Code is as follows: requestPermission requests desktop notifications
CheckPermission check the desktop notification license (PERMISSION_ALLOWED = 0, PERMISSION_NOT_ALLOWED = 1, PERMISSION_DENIED = 2)
CreateNotification create a desktop notification
Iii. desktop notification instances
Let's use this 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:
The Code is as follows: if (window. webkitNotifications ){
If (window. webkitpolicications. checkPermission () = 0 ){
SetInterval (function (){
Var popup = window. webkitNotifications. createNotification ("avator.jpg", "Please note:", "the computer will be blind for a long time. Take a break ~! ");
Popup. show ();
}, 1000*60*20); </p> <p >}else {
Window. webkitconfigurications. requestPermission ();
}
} Else {
Alert ('browser does not support desktop notifications ~! ');
}
Then the desktop will appear in 20 minutes: