Google Chrome扩展程序获取页面信息 [英] Google Chrome Extension get page information

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

问题描述

我正在制作Google Chrome浏览器扩展程序,并且需要获取当前网页的网址和标题。

I'm making a google chrome extension, and I need to get the current page URL and title. How can I achieve this?

推荐答案

chrome.tabs.getSelected(null, function(tab) { //<-- "tab" has all the information
    console.log(tab.url);       //returns the url
    console.log(tab.title);     //returns the title
});

欲了解更多信息,请阅读 chrome.tabs 。关于选项卡对象,请阅读此处

For more please read chrome.tabs. About the tab object, read here.

注: chrome.tabs.getSelected 已被弃用 自Chrome 16以来。正如文档中的建议, chrome.tabs.query() 应与参数 {'active':true} 一起使用以选择活动选项卡。

Note: chrome.tabs.getSelected has been deprecated since Chrome 16. As the documentation has suggested, chrome.tabs.query() should be used along with the argument {'active': true} to select the active tab.

chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
    tabs[0].url;     //url
    tabs[0].title;   //title
});

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

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