我的Chrome擴展中有一個通知功能,由後臺頁面管理(background.html) 此頁面調用setNotificationDelay()函數,該函數基本上是前一個定時器的刪除,後面跟着一個setTimeOut。setTimeOut在Chrome擴展中的作用域
function setNotificationDelay() {
clearNotificationTimer();
newDelay = getNotificationDelay()
notificationTimer = setTimeout(showNotification, newDelay);
}
}
我也有一個options.html頁面,允許配置通知小時。我想在修改配置時修改後臺超時,但是當我從Option頁面調用setNotificationDelay()時,它不起作用,並且我認爲這是因爲定時器的作用域連接到父頁面。
如果我讓選項頁面打開超時被觸發,如果我關閉它通知從未發生。
如何將此計時器附加到後臺頁面? 有沒有更好的方法來實現它?
謝謝。
編輯:chrome.extension有它返回的窗口對象爲背景的網頁頁面的getBackground方法:
function setNotificationDelay() {
clearNotificationTimer();
newDelay = getNotificationDelay()
notificationTimer = chrome.extension.getBackgroundPage().setTimeout(showNotification, newDelay);
}
}