The specific code is shown below:
<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 (notification.p ermice! = Denied) {notification.requestPermission (). THEN (Function (Permission) {PopNotice ()})}}; function popnotice () {if (notification.permission == Granted) {VAR NOTIFICATION = New Notification (Hello, hellos :, {body: Is there time tonight, icon : http: //image.zhangxinxu.com/ The left avatar address}); notification.Onclick = Function () {txt.innerhtml = new date (). split () [0]+receive information; captain .close ();}}} Else {console.log (the browser does not support Notification);}});
Notification.RequestPerMission () is a request that allows the browser to appear the prompt that allows notifications to notify the notification as the notification of notification.permission.
SummarizeThe above is the HTML5 implementation desktop notification prompt function introduced by Xiaobian. I hope it will be helpful to everyone. If you have any questions, please leave me a message. Xiaobian will reply to everyone in time. Thank you very much for your support for the VEVB Wulin website!