2013-08-24 17 views
3

我發現了用於Chrome應用程序豐富通知的documentation
是否有可能(獲得正確的權限後)在常規網頁中使用這些通知?
如果沒有,是否還有其他類型的桌面通知可以在Chrome中使用?
也許像gmail一直在做很長一段時間?正常網頁中的Chrome Rich Notifications?

+1

這將是[chrome桌面通知](http://www.chromium.org/developers/design-documents/desktop-notifications/api-specification)另請參閱http://stackoverflow.com/questions/2271156/鉻桌面通知,例如 –

回答

4

所以你需要這樣的東西?

Try it!

<script> 
function notify() { 
    var havePermission = window.webkitNotifications.checkPermission(); 
    if (havePermission == 0) { 
    // 0 is PERMISSION_ALLOWED 
    var notification = window.webkitNotifications.createNotification(
     'http://test.didacticmedia.ro/img/didactic.png', 
     'Notification test!', 
    'details text' 
    ); 

    notification.onclick = function() { 
     window.open("http://stackoverflow.com/questions/18414462/chrome-rich-notifications-in-normal-web-pages/19031405#19031405"); 
     notification.close(); 
    } 
    notification.show(); 
    } else { 
     window.webkitNotifications.requestPermission(); 
    } 
} 
</script> 

<div style="width: 100px; height: 100px; background: red" onclick="notify()"> 
Click here! 
</div> 
0

豐富的通知似乎是在常規的網頁不可用。我基於這一點,他們使用chrome.notifications,這是在正常的Chrome瀏覽器窗口中未定義的事實。 (如果有解決方法,我想知道)。

您可以使用常規的Notification對象,該對象似乎是一個新標準,儘管它遠沒有「豐富」,並且在所有瀏覽器中都不相同。例如,在Chrome中,通知會一直保持到用戶解散它爲止,而在Firefox中,它只會停留在屏幕上幾秒鐘。