Rob
Rob

Reputation: 137

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? I try onclick function, but it work's only few seconds. 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>'
});

Upvotes: 8

Views: 8122

Answers (2)

Siddharth
Siddharth

Reputation: 545

add dir : "ltr" in Options

    options = {
     dir : "ltr",
    icon: "images/images.jpg",
    body : "hello WOrld"

    }

new Notification("Current Notify",options);

Upvotes: -3

JasonCG
JasonCG

Reputation: 879

Unfortunately there is no support for links and other markup in HTML notifications. The only method to get a clickable link with a notification is to use 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

Firefox has a short duration for notifications compared to Chrome. There is no way to control how long a notification is visible in Firefox.

Upvotes: 10

Related Questions