0
我仍在學習如何創建Chrome擴展程序,但我的問題是使用桌面通知。我能夠觸發通知,但是當發生這種情況時,我會觸發內容腳本1的桌面通知。桌面通知也會觸發內容腳本2.我如何使它不會同時觸發,以及只有當他們被稱爲?同時發送一個Chrome擴展程序桌面通知
背景頁面
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
// Create a simple text notification
var notifyWinner = webkitNotifications.createNotification('48.png', 'Notification', request.winnerMessage);
notifyWinner.show();
setTimeout(function(){ notifyWinner.cancel(); },10000);
});
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
// Create a simple text notification
var notifyVideo = webkitNotifications.createNotification('48.png', 'Notification', request.videoMessage);
notifyVideo.show();
setTimeout(function(){ notifyVideo.cancel(); },10000);
});
內容腳本1
chrome.extension.sendRequest({winnerMessage: "You won!!!"}, function(response) {
return response;
});
內容腳本2
chrome.extension.sendRequest({videoMessage: "There is a video" + videoURL}, function(response) {
return response;
});
謝謝你正是我一直在試圖完成 – 2012-04-28 15:09:44
onRequest和sendRequest將已過時,需要用的onMessage和的sendMessage被替換 – DivZero 2014-05-10 14:13:16