HTML5 Notification (desktop Reminder) function instance

Source: Internet
Author: User

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:


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.