菜单切换
FACESOHO知行者
心灵
记录
远方
赞赏工具
源代码:
点击运行
保存
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>FACESOHO知行者 - 学以致用 知行合一 止于至善</title> <meta name="keywords" content="知行者启蒙 , 送人玫瑰,手有余香"> <meta name="description" content="知行者,启蒙心得,做善良的国人,facesoho官网"> <meta name="mobile-web-app-capable" content="yes" /> <link href="//cdn.staticfile.org/normalize/7.0.0/normalize.min.css" rel="stylesheet"> <link href="//cdn.staticfile.org/twitter-bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="//cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.min.css" media="all" /> <meta name="apple-mobile-web-app-title" content="FACESOHO知行者"> </head> <body> <div class="container-fluid"> <div class="text-center bg-danger text-white jumbotron"> 正确的网址 https://www.facesoho.com/demos/firefox-notification.html <br>浏览器通知 Notifications 桌面通知 <button id="button">激活桌面通知</button> <p id="text">第二步点 桌面通知 看反馈</p> </div> <script> if (window.Notification) { var button = document.getElementById('button'), text = document.getElementById('text'); var popNotice = function() { if (Notification.permission == "granted") { var notification = new Notification("Hi,帅哥:", { body: '可以加你为好友吗?', icon: '//image.zhangxinxu.com/image/study/s/s128/mm1.jpg' }); notification.onclick = function() { text.innerHTML = '张小姐已于' + new Date().toTimeString().split(' ')[0] + '加你为好友!'; notification.close(); }; } }; button.onclick = function() { if (Notification.permission == "granted") { popNotice(); } else if (Notification.permission != "denied") { Notification.requestPermission(function (permission) { popNotice(); }); } }; } else { alert('浏览器不支持Notification'); } </script> </body> </html>
运行结果