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> 相关推荐
86417413 2020-11-25
simonzhao0 2020-11-23
HappyBlog 2020-10-27
del 2020-10-21
ChromeDisaster 2020-10-11
svap 2020-08-25
simonzhao0 2020-08-17
shayuchaor 2020-08-17
yidaizongshi 2020-08-16
化风 2020-08-14
tiankele0 2020-07-29
maowenbei 2020-07-19
curiousL 2020-07-18
王练 2020-07-18
liuweiq 2020-07-08