admin管理员组文章数量:1023263
The Notification.requestPermission()
has 3 possible results: granted
, denied
and default
.
In Chrome you get default
when the user close the permission dialog using the X instead of explicitly saying block
. But, if after getting default
as result, you call Notification.permission
you get denied
, making impossible to retry asking permission again in the future.
It this by design? is there a way to make chrome treating differently this two results? Firefox treats this in the right way (you can ask permissions until the user explicitly denied it)
The Notification.requestPermission()
has 3 possible results: granted
, denied
and default
.
In Chrome you get default
when the user close the permission dialog using the X instead of explicitly saying block
. But, if after getting default
as result, you call Notification.permission
you get denied
, making impossible to retry asking permission again in the future.
It this by design? is there a way to make chrome treating differently this two results? Firefox treats this in the right way (you can ask permissions until the user explicitly denied it)
Share Improve this question asked Nov 13, 2017 at 12:04 ColucciniColuccini 7281 gold badge7 silver badges19 bronze badges1 Answer
Reset to default 8I'll leave this just in case someone is looking for an answer:
When the user had closed the permission dialog for the third time Chrome will automatically set the permission to denied
(it shows a automatically blocked
message below on the permission popup from the navbar). So the first three times the user close the dialog you gets default
as result, but on the third time the permission are set to denied
.
The way I'm using to work with this logic is:
window.Notification.requestPermission().then((result) => {
if (result === 'denied') {
// the user has denied permission
return;
}
if (result === 'default') {
// the user has closed the dialog
if (window.Notification.permission === 'denied') {
// the browser has decided to automatically denied permission
}
return;
}
// the user has granted permission
});
The Notification.requestPermission()
has 3 possible results: granted
, denied
and default
.
In Chrome you get default
when the user close the permission dialog using the X instead of explicitly saying block
. But, if after getting default
as result, you call Notification.permission
you get denied
, making impossible to retry asking permission again in the future.
It this by design? is there a way to make chrome treating differently this two results? Firefox treats this in the right way (you can ask permissions until the user explicitly denied it)
The Notification.requestPermission()
has 3 possible results: granted
, denied
and default
.
In Chrome you get default
when the user close the permission dialog using the X instead of explicitly saying block
. But, if after getting default
as result, you call Notification.permission
you get denied
, making impossible to retry asking permission again in the future.
It this by design? is there a way to make chrome treating differently this two results? Firefox treats this in the right way (you can ask permissions until the user explicitly denied it)
Share Improve this question asked Nov 13, 2017 at 12:04 ColucciniColuccini 7281 gold badge7 silver badges19 bronze badges1 Answer
Reset to default 8I'll leave this just in case someone is looking for an answer:
When the user had closed the permission dialog for the third time Chrome will automatically set the permission to denied
(it shows a automatically blocked
message below on the permission popup from the navbar). So the first three times the user close the dialog you gets default
as result, but on the third time the permission are set to denied
.
The way I'm using to work with this logic is:
window.Notification.requestPermission().then((result) => {
if (result === 'denied') {
// the user has denied permission
return;
}
if (result === 'default') {
// the user has closed the dialog
if (window.Notification.permission === 'denied') {
// the browser has decided to automatically denied permission
}
return;
}
// the user has granted permission
});
版权声明:本文标题:javascript - Chrome treats 'default' result from Notification.requestPermission() as 'denied' - 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745535075a2154923.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论