Google Chrome extension to close notification after user click

Viewed 4502

The Chrome extension works fine. My problem is that the notification closes in 7 seconds. I want for the user click to close the notification.

function engine(){
    var latestId;
    var ids;
    var messages = [];
    var newmessage = [];

    $.get('http://localhost/site/json.php',function (data){
        var json = $.parseJSON(data);
        messages = json;
        ids = json[0].id;
        if(latestId == ids){
            //no update
        }else if(latestId === undefined){
            var run = {
                type: "basic",
                title: "Title",
                message: "Some message",
                iconUrl : "icon.png",
            };

            chrome.notifications.create(run);
        }    
    });
}
4 Answers

notification.close() is used to close any notification.

For more information please see the below code-

To create the notification:

var notification = new Notification('OnlineOfferPrice', {
    icon: 'icon.png',
    body: "Test Message",
});

If you want to perform operation on notification click please use the below code. After your business logic it will automatically close-

notification.onclick = function () { 
    //write your business logic here.
    notification.close();
};

If notification is not clicked and you want to close it automatically after 6 seconds-

setTimeout(function() { notification.close(); }, 6000);
Related