我的网站目前在第一次访问网站时向用户发送推送通知,是否有办法删除此推送通知请求?
TIA
在你的.js文件中使用
Notification.requestPermission();
为"启用通知"创建按钮在。html文件
<button id="enable">Enable notifications</button>
当按下此按钮时,应用程序请求通知应用程序(.js文件)
function askNotificationPermission() {
// Asking for permissions
function handlePermission(permission) {
// button set for shown or hidden, depending on the user's selection
if(Notification.permission === 'denied' || Notification.permission === 'default') {
notificationBtn.style.display = 'block';
} else {
notificationBtn.style.display = 'none';
}
}
// Check if the browser actually supports notifications
if (!('Notification' in window)) {
console.log("This browser does not support notifications.");
} else {
if(checkNotificationPromise()) {
Notification.requestPermission()
.then((permission) => {
handlePermission(permission);
})
} else {
Notification.requestPermission(function(permission) {
handlePermission(permission);
});
}
}
}