admin管理员组文章数量:1335160
There is a basic example that shows how Notifications Web API works.
The example works well in Windows and Linux with Firefox/Chrome web browsers.
However, the example doesn't show any notifications in Android with Chrome/Brave web browsers.
I cannot find any information in Web API documentation of how to use Notifications in Android. As well, there is no any direct information that Notifications API doesn't work in Android.
Does Android supports the Web API Notifications?
URL of the example
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Notifications example</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Bootstrap/JQuery. -->
<link rel="stylesheet" href="/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous" />
<script src="/[email protected]/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-+sLIOodYLS7CIrQpBjl+C7nPvqq+FbNUBDunl/OZv93DB7Ln/533i8e/mZXLi/P+" crossorigin="anonymous"></script>
</head>
<body class="container mt-3">
<h2 class="mt-5">Notifications example</h2>
<p>This example use only JavaScript. No server side used.</p>
<input type="button" id="subscribe" value="Subscribe" class="btn btn-success" /><br />
<button onclick="notifyMe()" class="btn btn-info mt-3">Notify me!</button>
<button onclick="notifyMeWith7SecDelay()" class="btn btn-info mt-3">Notify me with 7 sec delay!</button>
<script>
$("#subscribe").on("click", function () {
let promise = Notification.requestPermission();
});
function notifyMe() {
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
} else if (Notification.permission === "granted") {
const notification = new Notification("Hi there!", {
body: "Is an example of a notification"
});
} else if (Notification.permission !== "denied") {
Notification.requestPermission().then((permission) => {
if (permission === "granted") {
const notification = new Notification("Hi there!", {
body: "Is an example of a notification"
});
}
});
}
}
function notifyMeWith7SecDelay() {
setTimeout(notifyMe, 7000);
}
</script>
</body>
</html>
本文标签: javascriptHow to use Notifications Web APIStack Overflow
版权声明:本文标题:javascript - How to use Notifications Web API - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742382782a2464425.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论