0

Chromeの進行状況リッチ通知を作成しようとしましたが、ステータスバーは移動しません。Chrome Progressリッチ通知ステータスが上に移動しない

私はこのコードがうまくいくと思います。ステータスバーは40msごとに1%ずつ上がります。通知は4秒後に消えます(100%にもなります)。私は私のsetInterval

var notifyStatus = function(title, message) { 
    var k = 0; 
    chrome.notifications.create('', { 
    'type': 'progress', 
    'iconUrl': 'images/icon128.png', 
    'title': title, 
    'message': message || '', 
    'progress': setInterval(function() { 
     if (k>100) {k;} 
     else {k++;} 
    },40) 
    }, function(nid) { 
    // Automatically close the notification in 4 seconds. 
    window.setTimeout(function() { 
     chrome.notifications.clear(nid); 
    }, 4000); 
    }); 
}; 
+1

あなたはK ' 'で何をしますか?あなたは 'setInterval'を正しく呼んでいますが、' k'の値を変更する以外は、実際には私が見ることのできるものは何もしていません。 – Kevin

答えて

2

に何か問題現在、あなたはどんな一度だけを返すのsetInterval値にprogressを代入しているがあると思います。

あなたはchrome.notifications.updateを使用して、新しいプログレス値で通知を各40msのを更新する必要があります。

var notifyStatus = function(title, message, timeout) { 
    chrome.notifications.create({ 
    type: 'progress', 
    iconUrl: 'images/icon128.png', 
    title: title, 
    message: message || '', 
    progress: 0 
    }, function(id) { 
    // Automatically close the notification in 4 seconds by default 
    var progress = 0; 
    var interval = setInterval(function() { 
     if (++progress <= 100) { 
     chrome.notifications.update(id, {progress: progress}, function(updated) { 
      if (!updated) { 
      // the notification was closed 
      clearInterval(interval); 
      } 
     }); 
     } else { 
     chrome.notifications.clear(id); 
     clearInterval(interval); 
     } 
    }, (timeout || 4000)/100); 
    }); 
}; 
+0

これはikeの魔法を働かせます。助けてくれてありがとう。 – johnmayer

関連する問題