2013-10-14 4 views
0

시간 초과되면 자동으로 닫히는 알림이 표시됩니다.다음 알림이 표시되기 전에 현재 알림을 닫으시겠습니까?

하지만 일부 알림은 제한 시간이 끝나기 전에 시작됩니다.

그럼, 다음 알림이 표시되기 전에 어떻게 현재 알림을 닫을 수 있습니까?

나는 특정한 시간에 오직 하나만 표시하고 싶습니다.

배경 :

chrome.extension.onMessage.addListener(function(request, sender, sendResponse) { 

    var notify = webkitNotifications.createNotification('icon-48.png', 'Notification', request.message); 

    notify.show(); 
    setTimeout(function(){ notify.cancel(); },10000); 
}); 

CONTEXT :

chrome.extension.sendMessage({ 

    message: "Fetching stuff from " + thestuffname}, 
    function(response) { 
    return response; 
}); 

답변

1

시도는 글로벌 var에 통지하게,이 같은 새

만들기 전에 취소 할 :

var notify; 

chrome.extension.onMessage.addListener(function(request, sender, sendResponse) { 
    if(notify){ 
     notify.cancel(); 
    } 
    notify = webkitNotifications.createNotification('icon-48.png', 'Notification', request.message); 

    notify.show(); 
    setTimeout(function(){ notify.cancel(); },10000); 
}); 
+1

을 @kdrureidy 고마워! 광고 된대로 작동합니다. 다음으로, Ajax 호출이 성공적으로 완료되었을 때 통지를 취소하는 방법이 될 것이다. – user1452893

+0

나는 당신에게 행운을 빌어. – kdureidy

관련 문제