教程集 www.jiaochengji.com
教程集 >  前端编程  >  HTML5教程  >  正文 什么是Notifications?HTML5 Notifications桌面提醒

什么是Notifications?HTML5 Notifications桌面提醒

发布时间:2020-07-25   编辑:jiaochengji.com
教程集为您提供什么是Notifications?HTML5 Notifications桌面提醒等资源,欢迎您收藏本站,我们将为您提供最新的什么是Notifications?HTML5 Notifications桌面提醒资源

Notifications是HTML5的一个新特性~ 可以看看360电脑抢票,也是用Notifications提示的~,下面小编写了一个HTML5 Notifications桌面提醒,还是挺不错的哦!<!DOCTYPE html>

<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桌面提醒的详细内容,更多请关注教程集其它相关文章!

-->
  • 本文原创发布教程集,转载请注明出处,感谢您的尊重!
  • 您可能感兴趣的文章:
    什么是Notifications?HTML5 Notifications桌面提醒
    HTML5桌面通知提示功能的实现
    phonegap实现提示操作详解
    phonegap使用方法介绍(九)进行提示操作的四种方式
    html5桌面通知之Notification API详解
    使用travis进行持续集成golang项目
    html5是什么意思
    Laravel 中利用MailThief实现邮件发送例子
    详解如何通过H5唤起本地app
    迅雷影音内容更新提醒怎么关闭

    [关闭]
    ~ ~