我正在尝试将通知推送到移动浏览器。 我按照https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API
中的文档进行操作它正在桌面上的Chrome上工作,但它不适用于移动设备,即使文档说它应该。 我也试过这个例子https://jsbin.com/ziwod/2/edit?html,js,output,但它仍然不起作用。
您可以在下面找到我的代码:
<script type="text/javascript">
createNotification("Reminder", "TEST", [100, 0, 200])
function createNotification(text_before, title, vibration) {
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support system notifications");
}
// Let's check whether notification permissions have already been granted
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification(text_before, { body: title, vibrate: vibration });
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
var notification = new Notification(text_before, { body: title, vibrate: vibration });
}
});
}
}
</script>
这适用于桌面设备,但不适用于移动设备。 谢谢你的时间!