我正在尝试在获取当前tabid后打开一个新标签,以便我可以通过 从新打开的标签到上一个标签的消息, 我这样做:
myscr.js:
var myvar = 0;
chrome.tabs.query({
currentWindow: true,
active: true
}, function (tabs) {
console.log(tabs[0]);
myvar = tabs[0].id;
//console.log(myvar);
});
var string_url = "getfilehandler.html/?" + "tabid=" + myvar;
window.open(string_url);
的manifest.json:
"permissions": [
"tabs",
"contextMenus", "fileBrowserHandler"
],
"content_scripts": [
{
"matches": ["file:///home/user/Desktop/itproject/test.html"],
"js": ["myscr.js"]
}
],
我的问题是当我打开文件test.html
时,浏览器似乎没有
发生!
当我在window.open(...)
中使用myscr.js
时,会打开新窗口。我不确定为什么会这样!任何帮助将不胜感激!
的变化:
chrome.tabs.query({
active: true, // Select active tabs
windowId: chrome.windows.WINDOW_ID_CURRENT // In the current window
}, function(array_of_Tabs) {
// Since there can only be one active tab in one active window,
// the array has only one element
var tab = array_of_Tabs[0];
// Example:
var url = tab.url;
console.log(url);
// ... do something with url variable
});