0

I'm building a chrome extension that submits links to an aggregation website. In order to do this, I need to get the URL from the currently open window, which I'm trying to do with this code:

chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
    var url = tabs[0].url;
    ...
});

This works fine with only one window open, but it seems to select the active tab from the first opened window when I have more than one open, rather than from the last focused window. I have tried using currentWindow also, but that seems to have the same problem.

Any help would be greatly appreciated!

4

2 回答 2

0

您的问题似乎与以下问题非常相似,请看一下。

来自问题的有用代码示例:

chrome.tabs.getSelected(null, function(tab) { document.getElementById('currentLink').innerHTML = tab.url; });

还要注意关于

不允许内联脚本和事件处理程序

(在 Chrome 扩展程序中)

希望这能让你走上正确的轨道!

因我的不良格式和不熟悉 SO 格式而编辑。

于 2013-09-09T13:23:22.427 回答
0

事实证明,问题在于我有 2 个版本的扩展:一个带有未打包的文件,另一个打包为 .crx 文件。我正在更新解压缩的代码,但我在浏览器中加载的版本是已经打包的版本。所以我的改变当然没有得到反映。通过确保我正在使用解压版本进行测试来解决。

于 2013-09-09T13:30:34.723 回答