這是一個可讓網頁在最小化時仍能夠顯示通知的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一塊兒,實現頁面關掉了也能夠發送通知
發現本身這樣貧瘠荒蕪的靈魂