今天驚奇的發現,chrome22里已經不支持window.webkitNotifications.createHTMLNotification方法了:
但是,在chrome extension里還可以繼續使用,比如fehelper里的頁面性能檢測功能:
Google這是要干嘛?逐步實現自己的w3c標准化?
Web Notification在w3c中確實沒有createHTMLNotification這樣的方法,甚至沒有createNotification。
而是一個及其簡單構造器:
var
notification =
new
Notification(
"我的消息"
,{
body :
'內容'
,
iconUrl :
'圖標'
,
tag : {},
// 可以加一個tag
});
notification.show();
|
貌似目前也只有chrome里面才有這個API:
改寫后為:
<!DOCTYPE html> <html> <head> <title>Google 桌面通知</title> <meta name="generator" content="editplus" /> <meta name="author" content="" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <meta http-equiv='content-type' content='text/html; charset=utf-8' /> </head> <body> <button id='btn'>顯示桌面通知</button> <script type='text/javascript'> document.querySelector("#btn").addEventListener('click', notify, false); function notify() { if (window.webkitNotifications) { console.log(123); if (window.webkitNotifications.checkPermission() == 0) { var notification_test = window.webkitNotifications.createNotification("http://images.cnblogs.com/cnblogs_com/flyingzl/268702/r_1.jpg", '標題', '內容'+new Date().getTime()); notification_test.display = function() {} notification_test.onerror = function() {} notification_test.onclose = function() {} notification_test.onclick = function() {this.cancel();} notification_test.replaceId = 'Meteoric'; notification_test.show(); var tempPopup = window.webkitNotifications.createHTMLNotification(["http://www.baidu.com/", "http://www.soso.com"][Math.random() >= 0.5 ? 0 : 1]); tempPopup.replaceId = "Meteoric_cry"; tempPopup.show(); } else { window.webkitNotifications.requestPermission(notify); } } else { console.log(456); var notification = new Notification("我的消息",{ body : '內容', iconUrl : 'https://dn-st.b0.upaiyun.com/v4.9.x/images/49751d86.touch-icon-ipad.png', tag : {} // 可以加一個tag }); notification.show(); } } </script> </body> </html>
注:以上紅色部分為新增chrome新版彈窗通知功能