chrome浏览器的桌面通知规范desktop notifications

 

原文链接:http://www.javaarch.net/jiagoushi/663.htm

 

W3C specification:http://www.w3.org/TR/notifications/ 这是w3c的最新的浏览器桌面通知的规范,现在只有chrome支持w3c的较低版本的桌面通知规范,http://www.chromium.org/developers/design-documents/desktop-notifications/api-specification,

 

创建桌面通知会有两步骤:

1.需要获得用户的允许网站允许发送桌面通知到桌面;

2. 如果用户允许,你则可以使用chrome的桌面API发送一个桌面通知给用户。

 

这是一个示例地址:http://www.smartjava.org/examples/notifications

代码如下:可以自己放在chrome试试。

 

firefox需要这个插件的支持:https://addons.mozilla.org/en-us/firefox/addon/html-notifications/

 

	<!DOCTYPE html>
	<html>
	<head>
		<title>Simple Webkit notification example</title>
	</head>
	 
	<h2>First click the 'request permission' button</h2>
	<button id="request">Request permission</button>
	<h2>After permission is granted, click the 'show notification' button</h2>
	<button id="show">Show notification</button>
	 
	<script type="text/javascript">
	 
	 
		document.getElementById('request').addEventListener('click', function() {
			window.webkitNotifications.requestPermission();
		}, false);
	 
	 
		document.getElementById('show').addEventListener('click', function() {
			showNotification();
		}, false);
	 
		function showNotification() {
			// only show if we've got the correct permissions
			if (window.webkitNotifications.checkPermission() === 0) {
				// note the show()
				window.webkitNotifications.createNotification('images/email.jpg', 'Plain Text Notification', 'Notification from the browser!').show();
			}
		}
	</script>
	</html>

 

转载于:https://www.cnblogs.com/zhwj184/archive/2013/05/31/3119595.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值