【问题标题】:How can I get the description and the url picture for a Google Chrome tab?如何获取 Google Chrome 标签的描述和 URL 图片?
【发布时间】:2014-02-11 22:12:25
【问题描述】:

我正在使用 Google Chrome 扩展程序,我只想知道如何将当前选项卡的描述和 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;
});

但仍然无法像这样存储来自balise meta的描述和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">

【问题讨论】:

  • 您能否提供更多详细信息,例如您正在使用的网站?网址图片是什么意思?

标签: javascript google-chrome-extension google-chrome-devtools


【解决方案1】:

我为 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; };

【讨论】:

    【解决方案2】:

    试试这个 jQuery 解决方案:

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

    来源:Jquery: Get favicon with full path

    【讨论】:

    • 那么它不是一个网站图标。但是试试var imageUrl = $('link[property="og:image"]')[0].href;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-15
    • 2023-02-05
    • 2022-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多