在Chrome扩展中显示当前URL

在Chrome扩展中显示当前URL

本文介绍了在Chrome扩展中显示当前URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  var outUrl; 
//首先获取windowid
chrome.windows.getCurrent(function(window){
//然后获取窗口中的当前活动标签
chrome.tabs.query( {
active:true,
windowId:window.id
},function(tabs){
var tab = tabs [0];
document.write(tab .url)
});
});

这是从我弹出的html文件中调用的JavaScript文件。它不显示当前网站的网址,而是不显示任何内容。



我在这个网站和其他网站上发现了多篇关于此的文章,但我没有已经能够实施任何假设的解决方案。



任何帮助将不胜感激。

解决方案



  chrome.tabs.query({' active':true,'windowId':chrome.windows.WINDOW_ID_CURRENT},
function(tabs){
alert(tabs [0] .url);
}
);


After doing some research, the code that I have come up with is this:

var outUrl;
// first get the windowid
chrome.windows.getCurrent(function(window) {
    // then get the current active tab in that window
    chrome.tabs.query({
        active: true,
        windowId: window.id
    }, function (tabs) {
        var tab = tabs[0];
        document.write(tab.url)
    });
});

This is in a javascript file which is called from my popup html file. It does not, however display the URL of the current website, instead it displays nothing.

I have found multiple posts about this on this and other websites but I haven't been able to implement any of the supposed solutions.

Any help would be greatly appreciated.

解决方案

Maybe this is what your looking for....

chrome.tabs.query({'active': true, 'windowId': chrome.windows.WINDOW_ID_CURRENT},
   function(tabs){
      alert(tabs[0].url);
   }
);

这篇关于在Chrome扩展中显示当前URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 03:14