获取 Chrome 扩展中选项卡的完整 URL
我正在尝试修改一个 chrome 扩展程序,该扩展程序将图像上传到 Picasa 并使用完整的 URL(例如 www.domain.com/whatever.jpg)标记它们,即它们上传的位置。
我在获取完整 URL 时遇到问题。当我尝试下面的代码时,它给了我一个不完整的 URL,只有 whatever.jpg,而不是 www.domain.com/
...
chrome.tabs.getSelected(null, function(tab) {
var yourell = tab.url;
...
有人有什么想法吗?
谢谢,
戴夫
I'm trying to modify a chrome extension which uploads images to Picasa and labels them with the complete URL e.g. www.domain.com/whatever.jpg, of where they were uploaded from.
I'm having problems with getting the complete URL. When i try the following bit of code, it gives me an incomplete URL with only the whatever.jpg, and not the www.domain.com/
...
chrome.tabs.getSelected(null, function(tab) {
var yourell = tab.url;
...
Anyone have any ideas?
Thanks,
Dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答
使用
chrome.tabs.getSelected 已被弃用。要获取当前活动选项卡的完整 URL,您需要使用 chrome.tabs.query 函数并执行类似以下
操作 示例
manifest.json
back.js
运行示例屏幕截图
加载示例扩展
单击扩展按钮,浏览器窗口打开到 exampley.com
扩展弹出窗口的控制台日志
示例文件 http://mikegrace.s3.amazonaws.com/stackoverflow/current-tab.zip
Answer
Use
chrome.tabs.getSelected has been deprecated. To get the full URL of the currently active tab you will want to use the chrome.tabs.query function and do something like this
Example
manifest.json
background.js
Running Example Screenshots
Load example extension
Clicking extension button with browser window opened to exampley.com
Console log of extension popup
Example files http://mikegrace.s3.amazonaws.com/stackoverflow/current-tab.zip