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!