-
Notifications
You must be signed in to change notification settings - Fork 4
/
simple-permissions.html
38 lines (37 loc) · 1.12 KB
/
simple-permissions.html
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
<!DOCTYPE html>
<html>
<head>
<title>Permissions API test page</title>
</head>
<body>
<h3>Permissions</h3>
<div><b>Geolocation:</b> <span id='geolocation'></span></div>
<div><b>Notifications:</b> <span id='notifications'></span></div>
<fieldset>
<legend>Requests</legend>
<button onclick="navigator.geolocation.getCurrentPosition(function(){});">Geolocation</button>
<button onclick="Notification.requestPermission();">Notifications</button>
</fieldset>
</body>
<script>
function updatePermission(name, state) {
console.log('update permission for ' + name + ' with ' + state)
document.getElementById(name).textContent = state;
}
function init() {
navigator.permissions.query({name:'geolocation'}).then(function(p) {
updatePermission('geolocation', p.state);
p.onchange = function() {
updatePermission('geolocation', p.state);
};
});
navigator.permissions.query({name:'notifications'}).then(function(p) {
updatePermission('notifications', p.state);
p.onchange = function() {
updatePermission('notifications', p.state);
};
});
}
init();
</script>
</html>