我試圖讓我的頁面動作圖標顯示在特定的網址上。我試過實現here的例子,但是這些需要trunk/dev版本。顯示頁面特定網址上的動作圖標
我現在的代碼取自a SO answer。但是這似乎不起作用,因爲該選項卡對象從未在我的測試中具有可限制的url屬性。
// background.js
function checkURL(tabId, info, tab) {
if (info.status === "complete") {
if (tab.url) {
// restrict here
chrome.pageAction.show(tabId);
}
}
}
chrome.tabs.onUpdated.addListener(checkURL);
//清單
{
"manifest_version": 2,
"name": "My first extension",
"version": "1.0",
"content_scripts": [
{
"matches": ["http://www.google.com/*"],
"js": [
"script.js"
],
"run_at": "document_idle"
}
],
"background": {
"page": "background.html",
"persistent": false
},
"page_action": {
"default_icon": "icon.png"
}
}
我在做什麼錯?
這裏是什麼的'〜tab.url.indexOf(」的含義。 pl')' –
'〜。「String」.indexOf(「S」)'是判斷字符串是否包含子字符串的智能方法。 '〜'爲'-1'返回0,即indexOf找不到匹配項。請參閱JS文檔中的〜運算符。 –