1 function notify() {
 2      if (window.webkitNotifications) {    //判断是否支持该功能
 3          if (window.webkitNotifications.checkPermission() == 0) {    //判断是否允许弹出桌面通知
 4              //文本模式创建通知
 5              var deskBox = window.webkitNotifications.createNotification('image.png', '标题', '内容');
 6              //当显示时调用
 7              deskBox.ondisplay = function(event) {
 8                  //自动关闭
 9                  setTimeout(function() {
10                      event.currentTarget.cancel();
11                  }, 10 * 1000);
12              };
13              //当出错时调用
14              deskBox.onerror = function() {};
15              //当关闭时调用
16              deskBox.onclose = function() {};
17              //当点击时调用
18              deskBox.onclick = function(event) {    
19                  //点击跳转页面
20                  window.focus();
21                  //关闭通知
22                  event.currentTarget.cancel();
23              };
24              //
25              deskBox.replaceId = 'box1';
26              //显示通知
27              deskBox.show();        
28              //关闭通知
29              //deskBox.cancel();    
30  
31              //URl模式创建通知            
32              var deskBox2 = window.webkitNotifications.createHTMLNotification("http://www.baidu.com/");
33              deskBox2.replaceId = "box2";
34              //延时显示通知
35              setTimeout(function(){
36                  deskBox2.show();
37              },5000);
38  
39          } else {
40              //询问用户是否允许提示
41              window.webkitNotifications.requestPermission(notify);
42          }
43  
44  
45      }
46  
47  }
posted on 2012-09-19 17:43  Cloud Lee  阅读(2102)  评论(0编辑  收藏  举报