[英]How can i add simple link in html5 desktop notification
How can i add simple link (a href) in html5 desktop notification on body section? 如何在正文部分的html5桌面通知中添加简单链接(a href)? I try onclick function, but it work's only few seconds.
我尝试onclick功能,但它的工作只有几秒钟。 If i try press later the notification just disappear and nothing do.
如果我稍后尝试按下通知就会消失,什么也没做。 So the best way would be with link.
所以最好的方法是链接。 I try that write, but then just print me as text.
我尝试写,但然后打印我作为文本。
var notification = new Notification('title', {
icon: '...',
body: '<a href="#">aaa</a>'
});
Unfortunately there is no support for links and other markup in HTML notifications. 遗憾的是,HTML通知中不支持链接和其他标记。 The only method to get a clickable link with a notification is to use onclick:
获取带有通知的可点击链接的唯一方法是使用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 has further documentation at https://developer.mozilla.org/en-US/docs/Web/API/notification Mozilla还有以下文档: https://developer.mozilla.org/en-US/docs/Web/API/notification
Firefox has a short duration for notifications compared to Chrome. 与Chrome相比,Firefox的通知持续时间较短。 There is no way to control how long a notification is visible in Firefox.
无法控制Firefox中可见的通知时长。
add dir : "ltr" in Options 在选项中添加目录:“ltr”
options = {
dir : "ltr",
icon: "images/images.jpg",
body : "hello WOrld"
}
new Notification("Current Notify",options);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.