我一直在瀏覽谷歌瀏覽器API,以便處理擴展和與之相關的過程。我偶然發現了chrome.webRequest https://developer.chrome.com/extensions/webRequest#event-onBeforeRequest我一直在修改語法,但我迷失了它,因爲我相對較新的編程和使用鉻APIssyntaxis在保存在擴展存儲上的數組的匹配URL上
我在想什麼是使用chrome.webRequest.onBeforeRequest。 addListener(函數回調),然後使其使用chrome.tabs.remove刪除選項卡是否匹配數組,但我不知道如何做到這一點
我有這個用於刪除使用谷歌瀏覽器的選項卡匹配過濾器
var urlArray= ["*://facebook.com/*", "*://example.com/*", "*://google.com/*" ];
chrome.tabs.onCreated.addListener(function (tab) {
for (var i = 0, len = urlArray.length; i < len; i++) {
if (tab.url.indexOf(urlArray[i]) > -1) {
chrome.tabs.remove(tab.id);
alert("things");
break;
}
}
});
你需要了解什麼'indexOf'一樣。 – Xan 2015-02-11 21:37:25
這可能會有所幫助,如果不是重複的話:http://stackoverflow.com/questions/12433271/can-i-allow-the-extension-user-to-choose-matching-domains – Xan 2015-02-11 21:38:16