如何在正文部分的html5桌面通知中添加简单链接(a href)?我尝试onclick功能,但它只工作了几秒钟。如果我稍后尝试按下通知就会消失,什么也没做。所以最好的方法是链接。我尝试写,但然后打印我作为文本。
var notification = new Notification('title', {
icon: '...',
body: '<a href="#">aaa</a>'
});
答案 0 :(得分:8)
不幸的是,HTML通知中不支持链接和其他标记。获取带有通知的可点击链接的唯一方法是使用onclick:
function makeNotification() {
var notification = new Notification('This is a clickable notification', {body: 'Click Me'});
notification.onclick = function () {
window.open("http://stackoverflow.com/");
};
}
function notifyMe() {
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
// Let's check if the user is okay to get some notification
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
makeNotification();
}
// Otherwise, we need to ask the user for permission
// Note, Chrome does not implement the permission static property
// So we have to check for NOT 'denied' instead of 'default'
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// If the user is okay, let's create a notification
if (permission === "granted") {
makeNotification();
}
});
}
}
Mozilla在https://developer.mozilla.org/en-US/docs/Web/API/notification
处有进一步的文档与Chrome相比,Firefox的通知时间较短。无法控制Firefox中通知的显示时间。
答案 1 :(得分:-2)
添加目录:&#34; ltr&#34;在选项中
options = {
dir : "ltr",
icon: "images/images.jpg",
body : "hello WOrld"
}
new Notification("Current Notify",options);