Chrome extension development: auto close the notification box

前端 未结 5 884
眼角桃花
眼角桃花 2021-01-02 16:35

After doing something I run this code:

var notification = webkitNotifications.createNotification(
   \'icon.png\',  // icon url - can be relative
  \'Done!\'         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-02 16:51

    //Use requireInternaction and set it to true for notification to not to auto-hide.
    
    function showNotification() {
        var options = {
            body: 'The Subtitles will Go Here',
            requireInteraction: true
        };
    
        if (window.Notification && Notification.permission !== "denied") {
           Notification.requestPermission(function (status) {  // status is "granted", if accepted by user
    
    var n = new Notification('Title', options);
            });
         }
    
       }
    

提交回复
热议问题