我在popup.html中使用带有按钮的chrome扩展程序,打开一个新标签页.新选项卡的目标URL将当前(原始)选项卡的URL保存为参数.
例如:当从中触发时http://stackoverflow.com/,新选项卡应该具有类似的URLhttp://www.mydestination.com/index.php?url=http://stackoverflow.com/
这是我的js:
document.addEventListener('DOMContentLoaded', function (tab) {
document.getElementById('button').addEventListener("click", function(tab) {
chrome.tabs.create({url: 'http://www.mydestination.com/index.php?url=' + tab.url});
});
})
Run Code Online (Sandbox Code Playgroud)
新选项卡完全打开,但URL为http://www.mydestination.com/index.php?url=undefined(url = undefined).
我认为manifest.json拥有正确的权限:
{
"manifest_version": 2,
"name": "My project",
"version" : "1.7",
"browser_action": {
"default_icon" : "img/icon.png",
"default_title" : "My project",
"default_popup": "html/main.html"
},
"permissions": [
"tabs"
],
"icons": {
"16": "img/icon.png"
}
}
Run Code Online (Sandbox Code Playgroud)
有关如何正确运输网址的任何线索?