Html5 desktop notification, notification usage, notification box in the lower right corner, html5notification

Source: Internet
Author: User

Html5 desktop notification, notification usage, notification box in the lower right corner, html5notification

1. Determine whether the browser supports window. Notification.

2. Check whether the browser has enabled the prompt permission: Notification. permission = 'granted' (if not, set Notification. requestPermission ())

3. Set the content of the prompt: var notification = new Notification ('order prompting ', {body: "You have a new order:" + data + ""}); // Notification ("title", "content ")

4. You can set other functions, such as message click events: notification. onclick = function (e ){
Alert ("click ")
}

Example:

If (window. notification) {if (Notification. permission = 'granted') {var notification = new Notification ('title', {body: "content can be customized by yourself"}); notification. onclick = function (e) {alert ("Click me") // you can click to open a URL} else {Notification. requestPermission (); // set the notification to be allowed }}

Extended: The configurable attributes of the content are as follows:

The available events are as follows:

  • Notification.onclickProcessingclickEvent processing. Triggered when a user clicks a notification.
  • Notification.onshowProcessingshowEvent processing. Triggered when the notification is displayed.
  • Notification.onerrorProcessingerrorEvent processing. The notification is triggered whenever an error occurs.
  • Notification.oncloseProcessingcloseEvent processing. Triggered when the user closes the notification.

How to disable the notification instance:

var n = new Notification(theTitle,options);  setTimeout(n.close.bind(n), 4000);

 

Note: ie does not support it. I have successfully tested it on Google and Firefox.

Record it when you develop your own data. If you pass by, please ignore it or give me some advice on what you need to pay attention to. Thank you.

 

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.