如何获取 chrome 扩展的当前标签 URL? [英] How can I get the current tab URL for chrome extension?

查看:82
本文介绍了如何获取 chrome 扩展的当前标签 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道关于 SO 有很多类似的问题,但我似乎无法让它发挥作用.

I know there are many similar questions on SO, but I cannot seem to get it working.

我正在尝试从我的 Chrome 扩展程序中获取当前选项卡的 URL.然而,警报(tab.url)返回未定义".我已在 manifest.json 中将选项卡"添加到我的权限中.有什么想法吗?

I am trying to get the URL of the current tab from my Chrome extension. Hoewever, the alert(tab.url) returns "Undefined". I have added the "tabs" to my permissions in the manifest.json. Any ideas?

<html>
<head>
<script>

    chrome.tabs.getSelected(null, function(tab) {
        tab = tab.id;
        tabUrl = tab.url;

        alert(tab.url);
    });

</script>
</head>

推荐答案

问题出在这一行:

tab = tab.id;

它应该是这样的:

var tabId = tab.id;

这篇关于如何获取 chrome 扩展的当前标签 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆