如何获取Chrome扩展的当前标签网址? [英] How can I get the current tab URL for chrome extension?
本文介绍了如何获取Chrome扩展的当前标签网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从我的网站获取当前标签的网址。
我知道在SO上有很多类似的问题,但我似乎无法得到它的工作。 Chrome扩展程序。 Hoewever,alert(tab.url)返回Undefined。我在manifest.json中为我的权限添加了选项卡。任何想法?
< 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;
I know there are many similar questions on SO, but I cannot seem to get it working.
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>
解决方案
The problem is in this line:
tab = tab.id;
It should be something like:
var tabId = tab.id;
这篇关于如何获取Chrome扩展的当前标签网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文