复制代码代码如下: dir: "" onclick: null onclose: null ondisplay: function (event) { onerror: null onshow: null replaceId: "" tag: "" __proto__: Notification addEventListener: function addEventListener() { [native code] } cancel: function cancel() { [native code] } close: function close() { [native code] } constructor: function Notification() { [native code] } dispatchEvent: function dispatchEvent() { [native code] } removeEventListener: function removeEventListener() { [native code] } show: function show() { [native code] } __proto__: Object
dir:设置消息的排列方向,可取值为 auto (自动), ltr (left to right), rtl (right to left)。 tag:为消息添加标签名。如果设置此属性,当有新消息提醒时,标签相同的消息只显示在同一个消息框,后一个消息框会替换先前一个,否则出现多个消息提示框,但是最多值显示3个消息框,超过3个,后继消息通知会被阻塞。 onshow:当消息框显示的时候触发该事件; onclick: 当点击消息框的时候触发该事件; onclose:当消息关闭的时候触发该事件; onerror:当出现错误的时候触发该事件; 方法: addEventListener removeEventListener:常规的添加和移除事件方法; show:显示消息提醒框; close:关闭消息提醒框; cancel:关闭消息提醒框,和 close一样; 4.createHTMLNotification() 该方法与 createNotification() 不同的是,他以HTML方式创建消息,接受一个参数: HTML 文件的URL,该方法同样返回 Notification对象。 一个实例:
复制代码代码如下: !DOCTYPE HTML html head title notifications in HTML5 /title /head body form input id="trynotification" type="button" value="Send notification" / /form script type="text/javascript" document.getElementById("trynotification").onclick = function(){ notify(Math.random()); }; function notify(tab) { if (!window.webkitNotifications) { return false; } var permission = window.webkitNotifications.checkPermission(); if(permission!=0){ window.webkitNotifications.requestPermission(); var requestTime = new Date(); var waitTime = 5000; var checkPerMiniSec = 100; setTimeout(function(){ permission = window.webkitNotifications.checkPermission(); if(permission==0){ createNotification(tab); }else if(new Date()-requestTime waitTime){ setTimeout(arguments.callee,checkPerMiniSec); } },checkPerMiniSec); }else if(permission==0){ createNotification(tab); } } function createNotification(tab){ var showSec = 10000; var icon = "http://tech.baidu.com/resource/img/logo_news_137_46.png"; var title = "[" + new Date().toLocaleTimeString() + "] close after " + (showSec/1000) + " seconds"; var body = "hello world, i am webkitNotifications informations"; var popup = window.webkitNotifications.createNotification(icon, title, body); popup.tag = tab; popup.ondisplay = function(event) { setTimeout(function() { event.currentTarget.cancel(); }, showSec); } popup.show(); } /script /body /html html教程