【发布时间】:2012-12-07 06:31:17
【问题描述】:
问题很简单:如果为chrome制作扩展名并使用
chrome.pageAction
要将图标放在地址栏中,此扩展程序在开发模式下不起作用。为什么不呢?
背景.html
<script language="javascript">
chrome.pageAction.onClicked.addListener(function (tab) {
chrome.tabs.executeScript(tab.id, {
file: "jquery.js"
}, function () {
chrome.tabs.executeScript(tab.id, {
code: '$[CODE JQUERY];'
});
});
});
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if(tab.url.indexOf("facebook.com") != -1) {
chrome.pageAction.show(tabId);
}
});
</script>
【问题讨论】:
-
你在哪里调用这个 API?请注意,您不能在内容脚本中使用它。
-
我在 background.html 中使用了这个
-
你需要显示你的后台脚本的代码。另外请调试后台页面并检查错误。
-
您不能在 HTML 中使用内联代码。您需要将其移动到某个外部文件(如 background.js)并使用
<script src='background.js'></script>将其包含在页面中。 -
好的,现在可以了!之前它只有在发布时才有效。你是我的参考点。谢谢@KonradDzwinel
标签: javascript html google-chrome-extension manifest google-chrome-devtools