首页 > 谷歌 notification 测试 页面

谷歌 notification 测试 页面

 1 <button onclick="notifyMe('master wei','http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png','我在测试谷歌通知功能','http://www.mi.com/')">通知!button>
 2 <script>
 3 var sum = 0;
 4 document.addEventListener('DOMContentLoaded', function () {
 5   if (!Notification) {
 6         alert('Desktop notifications not available in your browser. Try Chromium.'); 
 7         return;
 8   }
 9   if (Notification.permission !== "granted"){
10         Notification.requestPermission();
11   }
12 });
13 function notifyMe(title,iconurl,bodyContent,openurl) {
14     sum ++;
15     if (Notification.permission !== "granted"){
16         Notification.requestPermission();
17     }
18     else {
19         var notification = new Notification(title, {
20             icon: iconurl,
21             body: bodyContent+sum,
22         });
23         notification.onclick = function () {
24               window.open(openurl);      
25         };
26       }
27 }
28 script>

ios移动端不可用

Firefox 支持  ,但通知过多后会显示不完全

IE 不支持

转载于:https://www.cnblogs.com/wzk1992/p/6640253.html

更多相关: