-
Notifications
You must be signed in to change notification settings - Fork 0
/
Web-Notifications
51 lines (43 loc) · 1.76 KB
/
Web-Notifications
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
原文链接 http://www.html5cn.org/article-9794-1.html?utm_source=hao.caibaojian.com/
if (window.Notification) {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('safari') != -1) {
if (ua.indexOf('chrome') > -1) {
// Chrome
Notification.requestPermission().then(function(permission) {
if (permission == "granted") {
var notification = new Notification('桌面推送', {
body: '这是我的第一条桌面推送',
icon: 'some/icon/url'
});
notification.onclick = function() {
console.log('点击');
notification.close();
};
} else {
Notification.requestPermission();
console.log('没有权限,用户拒绝:Notification');
}
});
} else {
// Safari
Notification.requestPermission(function(permission) {
if (permission == "granted") {
var notification = new Notification('桌面推送', {
body: '这是我的第一条桌面推送',
icon: 'some/icon/url'
});
notification.onclick = function() {
console.log('点击');
notification.close();
};
} else {
Notification.requestPermission();
console.log('没有权限,用户拒绝:Notification');
}
})
}
}
} else {
console.log('不支持Notification');
}