HTML5 enables desktop notification and html5 enables desktop notification

Source: Internet
Author: User

HTML5 enables desktop notification and html5 enables desktop notification

The Code is as follows:

<Button id = "button"> someone wants to add you as a friend </button> <p id = "text"> </p>; (function () {if (window. notification) {var btn = document. getElementById ("button"); var txt = document. getElementById ("text"); btn. onclick = function () {if (Notification. permission = "granted") {popNotice ();} else if (Notification. permission! = "Denied") {Notification. requestPermission (). then (function (permission) {popNotice ()}) }; function popNotice () {if (Notification. permission = "granted") {var notification = new Notification ("Hello:", {body: "Are you free tonight?", icon :" http://image.zhangxinxu.com/ Profile picture address on the left "}); notification. onclick = function () {txt. innerHTML = new Date (). toTimeString (). split ("") [0] + "Receive message"; notification. close () ;}}} else {console. log ("the browser does not support Notification ");}})();

Notification. requestPermission () is a request for the browser to show whether to allow notifications and notifications. like permission, "3" values "granted" "default" "denied" are returned. The user is not authorized yet.

Summary

The above section describes how to implement the desktop notification prompt function in HTML5. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.