Pra*_*hat 10 javascript jquery push-notification progressive-web-apps polymer-3.x
我的要求是如何使用javascript(在不使用任何插件的情况下,如果此插件支持PWA应用程序,则只能使用该插件)在Android设备中检测设备级别通知的开/关。
根据通知是否关闭,我需要向用户显示弹出窗口,请启用通知功能,您将收到通知。
以下答案仅用于侦探性浏览器级别的通知。如果有人知道,请给我确切的答案。因为,我停在那里。
如果用户禁用,请检查此处用户启用的图像,如果用户禁用,则无法发送通知。
该功能似乎有详细记录,您尝试过吗:
function notifyMe() {
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
console.log("This browser does not support desktop notification");
}
// Let's check whether notification permissions have alredy been granted
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification("Hi there!");
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== 'denied' || Notification.permission === "default") {
Notification.requestPermission(function (permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
var notification = new Notification("Hi there!");
}
});
}
// At last, if the user has denied notifications, and you
// want to be respectful there is no need to bother them any more.
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
256 次 |
| 最近记录: |