admin管理员组文章数量:1125625
I have a larger scale site that I would implement this on, but for simplicity I have a basic html web page that has 2 buttons that push down a notification to the windows desktop. These appear in the banner one at a time. If you click both buttons, only a single notification appears with the last button clicked being the latest notification shown.
In the action centre these show up as multiple notifications all stacked on one another.
Is there a way to have both notifications, shown at the same time in the banner (on ontop of the other). I have looked everywhere for a solution and have found nothing, is this something that can be fixed via the javascript or is it a limitation of windows desktop notifications?
Currently hosting the site on Netlify so I do get the notifications etc.
<body>
<h1>Notification Tester</h1>
<button id="btn1">Notification 1</button>
<button id="btn2">Notification 2</button>
<script>
// Function to show notifications
function showNotification(title, body) {
// Request permission if not already granted
Notification.requestPermission().then((permission) => {
if (permission === "granted") {
// Create a new notification
new Notification(title, {
body: body,
icon: ".png"
});
}
});
}
// Add click event listeners to the buttons
document.getElementById("btn1").addEventListener("click", () => {
showNotification("Test 1", "This is test 1 notification");
});
document.getElementById("btn2").addEventListener("click", () => {
showNotification("Test 2", "This is test 2 notification");
});
</script>
本文标签: javascriptCreate stacking windows desktop notifications from chrome websiteStack Overflow
版权声明:本文标题:javascript - Create stacking windows desktop notifications from chrome website - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736643684a1946056.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论