如何获取谷歌浏览器标签的描述和网址图片



我有谷歌浏览器扩展名,我只想知道如何将当前选项卡的描述和网址图片存储在变量中。

我已经存储了带有以下说明的 url 和标题:

chrome.tabs.getSelected(null, function(tab) {
    document.getElementById('currentLink').innerHTML = tab.url;
});

chrome.tabs.getSelected(null, function(tab) {
    document.getElementById('currentTitle').innerHTML = tab.title;
});

但仍然无法像这样存储来自可莉丝元的描述和 url 图片:

<meta name="description" content="Le Monde.fr - 1er site d'information. Les articles du journal et toute l'actualit&eacute; en continu : International, France, Soci&eacute;t&eacute;, Economie, Culture, Environnement, Blogs ...">

<meta property="og:image" content="http://s1.lemde.fr/medias/web/1.2.639/img/placeholder/opengraph.jpg">

我为 Mozilla Firefox 做了同样的扩展......我用这段代码存储变量

var x = content.document.getElementsByTagName("meta"); for (var i=0;i<x.length;i++) { if (x[i].getAttribute("property") !=null) { if (x[i].getAttribute("property").toLowerCase() == "og:url") var url = x[i].content; if (x[i].getAttribute("property").toLowerCase() == "og:description") var description = x[i].content; if (x[i].getAttribute("property").toLowerCase() == "og:title") var title = x[i].content; if (x[i].getAttribute("property").toLowerCase() == "og:image") var image = x[i].content; };

试试这个jQuery解决方案:

var faviconUrl = $('link[rel="shortcut icon"]')[0].href;

来源: Jquery: 获取具有完整路径的图标

最新更新