这是一个可让网页在最小化时仍能够显示通知的apivue
效果的话能够看这个论坛的效果,登陆进去肯定给权限,等有人发消息就能够看到效果了git
右下角,api
这样在网页外面的一个通知的效果浏览器
这样在浏览器没有打开,焦点不在咱们的网页的时候也是能够发通知让用户看到的。url
使用的话要先申请权限spa
贴一段基本的示例代码3d
function notifyMe() { // Let's check if the browser supports notifications if (!("Notification" in window)) { alert("This browser does not support desktop notification"); } // Let's check whether notification permissions have already been granted else if (Notification.permission === "granted") { // If it's okay let's create a notification var notification = new Notification("Hi there!"); } // Otherwise, we need to ask the user for permission else if (Notification.permission !== "denied") { Notification.requestPermission(function (permission) { // If the user accepts, let's create a notification if (permission === "granted") { var notification = new Notification("Hi there!"); } }); } // At last, if the user has denied notifications, and you // want to be respectful there is no need to bother them any more. }
还有一些选项参看code
更易懂的看blog
兼容性get
这个能够和service worker+push API一块儿,实现页面关掉了也能够发送通知
发现本身这样贫瘠荒芜的灵魂