Chrome桌面通知
2016-12-06 15:31
211 查看
https://www.oschina.net/code/snippet_2012583_51015
开启桌面提醒:三道杠-显示高级设置-内容设置-通知-允许所有网站显示桌面通知
<!DOCTYPE html>
<html>
<head>
<title>Google 桌面通知</title>
</head>
<body>
<button onclick="notifyMe()">Notify me!</button>
<script type='text/javascript'>
function notifyMe() {
var title = "new message";
var options = {
body: "message content",
icon: "http://img.sobot.com/chatres/common/face/admin.png"
};
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
// Let's check whether notification permissions have already been granted
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification(title, options);
notification.onshow = function() {
setTimeout(function() {
notification.close();
}, 3000);
};
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
var notification = new Notification(title, options);
notification.onshow = function() {
setTimeout(function() {
notification.close();
}, 3000);
};
}
});
}
// At last, if the user has denied notifications, and you
// want to be respectful there is no need to bother them any more.
}
</script>
</body>
</html>
开启桌面提醒:三道杠-显示高级设置-内容设置-通知-允许所有网站显示桌面通知
<!DOCTYPE html>
<html>
<head>
<title>Google 桌面通知</title>
</head>
<body>
<button onclick="notifyMe()">Notify me!</button>
<script type='text/javascript'>
function notifyMe() {
var title = "new message";
var options = {
body: "message content",
icon: "http://img.sobot.com/chatres/common/face/admin.png"
};
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
// Let's check whether notification permissions have already been granted
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification(title, options);
notification.onshow = function() {
setTimeout(function() {
notification.close();
}, 3000);
};
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
var notification = new Notification(title, options);
notification.onshow = function() {
setTimeout(function() {
notification.close();
}, 3000);
};
}
});
}
// At last, if the user has denied notifications, and you
// want to be respectful there is no need to bother them any more.
}
</script>
</body>
</html>
相关文章推荐
- Chrome的桌面通知
- chrome 桌面通知
- 谷歌浏览器桌面通知 HTML5 Chrome Desktop Notifications
- chrome 桌面通知 Notifications 用法
- Chrome的桌面通知
- Chrome桌面通知功能Notifications对象
- Chrome插件:弹出桌面通知
- Chrome 桌面通知Notification
- HTML5桌面通知:notification api
- 完美兼容IE,chrome,ff的设为首页、加入收藏及保存到桌面js代码
- symbian 后台运行时 桌面 全局通知
- HTML5桌面通知:notification api
- window.Notification实现桌面通知
- centos7 创建桌面快捷方式(chrome,eclipse)
- 使用chrome添加网页到桌面
- 使用notify-send发送桌面通知
- Chrome 远程桌面
- javascript实现下班倒计时效果的方法(可桌面通知)
- javascript实现下班倒计时效果的方法(可桌面通知)
- 以带数字的小圆点方式显示在桌面图标上面,通知用户有新的消息--iOS开发