【发布时间】:2014-06-13 12:03:17
【问题描述】:
我创建了一个扩展,它会在弹出窗口中打开所有在 textarea 中输入的 URL。在最新的 chrome 版本中,它无法正常工作 - 有时它会打开所有输入的选项卡,但有时只打开其中的一部分。
我找到了一些信息,脚本需要移动到 background.js,这应该可以解决这个问题,但我不知道该怎么做。你能帮帮我吗?
manifest.js
{"name": "URL Opener",
"description": "",
"version": "1.0",
"icons": { "128": "url_128x128.png" },
"permissions": ["tabs", "http://*/*", "https://*/*", "background"],
"browser_action": {
"default_title": "URL Opener+",
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"background": {"scripts": ["background.js"],"persistent": false
},
"manifest_version": 2
}
popup.html
这里我只有那个文本区域和点击按钮
popup.js
document.addEventListener('DOMContentLoaded', function () {var divs1 = document.getElementById("button");divs1.addEventListener('click', URLopener);});
function URLopener () {var txt = document.getElementById("textfield").value;
for(i = 0; i < txt.length; i++){chrome.tabs.create({url: txt[i]});}
}
到目前为止它运行良好,但现在它不会总是打开所有标签...
我尝试将函数URLopener()移到background.js,但不知道具体怎么从popup.js调用,或者还有什么办法……
【问题讨论】: