notifications是html5的一个新特性~ 可以看看360电脑抢票,也是用notifications提示的~,下面小编写了一个html5 notifications桌面提醒,还是挺不错的哦!76c82f278ac045591c9159d381de2c57
<html>
<head>
<meta charset="utf-8">
<title>html5 - notifications</title>
<script>
//判断浏览器是否支持notifications
function supported(){
if(window.webkitnotifications){
alert('浏览器支持notifications');
} else {
alert('浏览器不支持notifications');
}
}
//请求桌面通知权限
function requestpermission() {
window.webkitnotifications.requestpermission();
}
//获取请求权限状态
function checkpermission() {
switch (window.webkitnotifications.checkpermission()) {
case 0:alert('用户已允许显示桌面通知');break;
case 1:alert('用户还没有允许或拒绝显示桌面通知');break;
case 2:alert('用户已拒绝显示桌面通知');break;
}
}
//创建文本消息
function textmsg(){
var icon = 'logo.png';
var title = '阿鹏\'s blog';
var body = 'http://www.1990c.com';
var popup = window.webkitnotifications.createnotification(icon, title, body);
popup.ondisplay = function(event) {
settimeout(function() {
event.currenttarget.cancel();
}, 5000);
}
popup.show();
}
//创建html消息
function htmlmsg(){
var popup = window.webkitnotifications.createhtmlnotification('msg.html');
popup.ondisplay = function(event) {
settimeout(function() {
event.currenttarget.cancel();
}, 5000);
}
popup.show();
}
</script>
</head>
<body>
<input type="button" value="是否支持桌面提醒" onclick="supported();"/>
<input type="button" value="请求权限" onclick="requestpermission();"/>
<input type="button" value="请求权限状态" onclick="checkpermission();"/>
<input type="button" value="显示文本消息" onclick="textmsg();"/>
<input type="button" value="显示html消息" onclick="htmlmsg();"/>
</body>
</html>
以上就是什么是notifications?html5 notifications桌面提醒的详细内容。