首页 文章

如何获取Google Chrome标签的说明和网址图片?

提问于
浏览
0

我正在使用Google Chrome扩展程序,我只想知道如何在变量中存储curent标签的说明和网址图片 .

我已经使用这些说明存储了网址和 Headers :

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">

2 回答

  • 0

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

    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; };
    
  • 0

    试试这个jQuery解决方案:

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

    资料来源:Jquery: Get favicon with full path

相关问题