我试图让我的页面动作图标显示在特定的网址上。我试过实现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文档中的〜运算符。 –