gpt4 book ai didi

javascript - 如何设置 HTML5 桌面通知的样式?

转载 作者:搜寻专家 更新时间:2023-10-31 08:28:19 25 4
gpt4 key购买 nike

我尝试为我的网站制作桌面通知,我找到了this指南很有用。并成功完成。

我也把代码贴在这里:

html:

<button id='button'>Notify me!</button>

js:

$('input[type=button]').click(notifyMe);

function notifyMe() {
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
} else if (Notification.permission === "granted") {
var options = {
body: "This is the body of the notification",
icon: "icon.jpg",
dir: "ltr"
};
var notification = new Notification("Hi there", options);
} else if (Notification.permission !== 'denied') {
Notification.requestPermission(function(permission) {
if (!('permission' in Notification)) {
Notification.permission = permission;
}

if (permission === "granted") {
var options = {
body: "This is the body of the notification",
icon: "icon.jpg",
dir: "ltr"
};
var notification = new Notification("Hi there", options);
}
});
}
}

Demo

我的问题是,有办法改变它的默认样式吗?

最佳答案

恐怕无法编辑比您正在做的更多的内容。就像警报元素一样,浏览器会格式化通知。

关于javascript - 如何设置 HTML5 桌面通知的样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30725070/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com