xx3*_*004 22 google-chrome-extension
我有关于编写Google Chrome扩展程序的问题.我现在的目标是检测是否创建了选项卡或选项卡的URL已更改.
实际上,我想从在线链接中插入字典.js到Chrome上的任何网页,该脚本将作为background.html运行.例如,如果您打开浏览器并转到主页,它将运行脚本以将dictionary.js插入该页面.创建新选项卡或打开新页面时,它也会运行脚本.当人们更改tab的url时,它也会运行脚本.如何在这种情况下检测标签是否发生变化?好的,这是我的...代码,我想,解释一下.
chrome.someFunctionThatDetectTheSituationsAbove(function() {
insertDictionaryScript();//I'd love to have the script of detection, not the insertDictionaryScript();
}
Run Code Online (Sandbox Code Playgroud)
任何想法我都会感激.谢谢.:P.
[X]
Sin*_*dar 54
只需在background.js上添加:
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
insertDictionaryScript();
});
chrome.tabs.onCreated.addListener(function(tab) {
insertDictionaryScript();
});
Run Code Online (Sandbox Code Playgroud)
kag*_*san 12
还有onActivated事件:
chrome.tabs.onActivated.addListener(function(tabId, changeInfo, tab) {
insertDictionaryScript();
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31709 次 |
| 最近记录: |