在Chrome扩展程序中获取当前网页网址 [英] Get current page URL in Chrome extension

查看:1680
本文介绍了在Chrome扩展程序中获取当前网页网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的 default_popup 页面中获取当前页面的URL,如下所示:

  chrome.tabs.query({active:true},function(tab){
url = tab.url;
});

我注册了这个 popup.html 页面位于 manifest.json 文件中。然而
我收到错误信息:

lockquote

未捕获类型错误:无法调用未定义的方法'查询'


我做错了什么?

解决方案

回调参数应该指定一个如下所示的函数:

  function(Tab结果数组){...} 

也许你应该这样写

  url = tab [0] .url; 


I want to get the current page URL from my default_popup page like this:

chrome.tabs.query({active:true},function(tab){
    url = tab.url;
});

And I have registered this popup.html page in the manifest.json file. Yet I am getting the error message:

Uncaught Type Error: Cannot call method 'query' of undefined

What am I doing wrong?

解决方案

The callback parameter should specify a function that looks like this:

function(array of Tab result){...}

Maybe you should write like this

url = tab[0].url;

这篇关于在Chrome扩展程序中获取当前网页网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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