2014-12-05 20 views
6

Vücut bölümünde html5 masaüstü bildiriminde nasıl basit bağlantı (bir href) ekleyebilirim? Seçme işlevini denerim, ama iş sadece birkaç saniyedir. Daha sonra basmaya çalışırsam, bildirim kaybolur ve hiçbir şey yapılmaz. Yani en iyi yol bağlantı ile olurdu. Yazmayı denerim, ama sonra sadece metin olarak yazdır.html5 masaüstü bildiriminde nasıl basit bağlantı ekleyebilirim

var notification = new Notification('title', { 
icon: '...', 
body: '<a href="#">aaa</a>' 
}); 

cevap

7

Maalesef HTML bildirimlerinde bağlantıları ve diğer biçimlendirme için destek yoktur. Bir bildirimle tıklanabilir bağlantı almak için tek yöntem onclick kullanmaktır:

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 Firefox Chrome ile karşılaştırıldığında bildirimleri için kısa süreye sahip https://developer.mozilla.org/en-US/docs/Web/API/notification

de ileri belgelerine sahiptir. Firefox'ta bir bildirimin ne kadar süre görünür olduğunu kontrol etmenin bir yolu yoktur.

+0

yılında karşılanması amacıyla Öncelikle teşekkürler. :) Bildirimler iyi çalışır, ancak sadece birkaç saniye, örneğin firefox bildirim gösterisinde ve birkaç saniye sonra otomatik olarak kaybolur, krom bildiriminde kalır ancak onclick birkaç saniye bekledikten sonra çalışmaya devam eder. Nedenini bilmiyorum. – Rob

+0

Evet, ilk başta Chrome’da test ettiğimde farketmedim ama daha sonra cevabımı ilk gönderdikten sonra Firefox’ta test ettim ve aynı şeyi gördüm. Firefox bildirimleri bu şekilde tasarlanmıştır, bu da can sıkıcıdır. Görünüşe göre, Add-On yapmak için SDK kullanıyor olsanız bile, http://stackoverflow.com/questions/20456377/modifying-the-timeout-of-notifications-in-a-firefox-extension ve https değiştirilemez. : //bugzilla.mozilla.org/show_bug.cgi? id = 875114 – JasonCG

+0

Kullanıcı her ne zaman kapatılıncaya dek bildirimi her kapatışınızda yeniden oluşturabilirsiniz: http://stackoverflow.com/questions/25209805/how -do-i-keep-a-bildirim-açık-içinde-firefox – JasonCG

-2

eklenti dir: "ltr" Seçenekler

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

    } 

new Notification("Current Notify",options); 
+0

'dir' ifadesi sadece dil yönünü belirler. ltr, soldan sağa doğru anlamına gelir. Bkz. [Doc] (https://developer.mozilla.org//docs/Web/API/Notification/dir) – Bludwarf

İlgili konular