如何创建通知chrome扩展?

时间:2013-09-14 02:16:56

标签: mysql google-chrome google-chrome-extension notifications

我想创建一个google chrome扩展程序,在添加mysql数据库中的新记录时通知用户!有人可以帮助我吗? 谢谢。

2 个答案:

答案 0 :(得分:8)

请参阅此页。

  

使用chrome.notifications API创建丰富的通知   模板并向系统托盘中的用户显示这些通知。

http://developer.chrome.com/extensions/notifications.html

chrome.notifications.create(
    'name-for-notification',{   
    type: 'basic', 
    iconUrl: 'image.jpeg', 
    title: "This is a notification", 
    message: "hello there!" 
    },

function() {} 

);

您可以创建这样的通知。

答案 1 :(得分:0)

您还可以像这样使用来自窗口对象的通知

而且-非常重要! :不要忘记在manifest.json

中添加“ notifications”权限
    function init() {
    
    
    if (!window.Notification) {

        alert('notSupport');
    } else if (Notification.permission === "granted") {
        console.log('grant notification')
        installNotification = createInstallNotification();

    } else if (Notification.permission !== 'denied') {
        console.log('denied init notes')
        Notification.requestPermission(function (permission) {
            console.log('ask init notes',permission)
            if (permission === 'granted') {

                installNotification = createInstallNotification();

            }else{
                alert('doNotDenied')
            }
        })

    }
    // end init
}
function createInstallNotification() {
    return new Notification('installSuccess', {
        body: 'text body'
        , tag: 'uniqe-numer-here'
    })
}
相关问题