javascript - How can i add simple link in html5 desktop notification -
how can add simple link (a href) in html5 desktop notification on body section? try onclick function, work's few seconds. if try press later notification disappear , nothing do. best way link. try write, print me text.
var notification = new notification('title', { icon: '...', body: '<a href="#">aaa</a>' });
unfortunately there no support links , other markup in html notifications. method clickable link notification use onclick:
function makenotification() { var notification = new notification('this clickable notification', {body: 'click me'}); notification.onclick = function () { window.open("http://stackoverflow.com/"); }; } function notifyme() { // let's check if browser supports notifications if (!("notification" in window)) { alert("this browser not support desktop notification"); } // let's check if user okay notification else if (notification.permission === "granted") { // if it's okay let's create notification makenotification(); } // otherwise, need ask user permission // note, chrome not implement permission static property // have check not 'denied' instead of 'default' else if (notification.permission !== 'denied') { notification.requestpermission(function (permission) { // if user okay, let's create notification if (permission === "granted") { makenotification(); } }); } }
mozilla has further documentation @ https://developer.mozilla.org/en-us/docs/web/api/notification
firefox has short duration notifications compared chrome. there no way control how long notification visible in firefox.
Comments
Post a Comment