用JS获取网站的图标 [英] Get website's favicon with JS
问题描述
我想知道是否可以通过使用JavaScript
的URL获取网站的网站图标.
I am wondering if it is possible to get a website's favicon by an URL with JavaScript
.
例如,我有一个URL http://www.bbc.co.uk/
,我想获取<link rel="icon" .../>
元标记-http://www.bbc.co.uk/favicon.ico
中所述的图标图标的路径.
For example I have an URL http://www.bbc.co.uk/
and I would like to get path to favicon described in <link rel="icon" .../>
meta tag - http://www.bbc.co.uk/favicon.ico
.
我有很多网址,因此不应加载每个页面并搜索我认为的link
标记.
I have many URLs so that should not load every page and search for link
tag I think.
有什么想法吗?
推荐答案
您可以为此使用YQL
You could use YQL for that
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D"http://bbc.co.uk/"and%20xpath%3D"/html/head/link[@rel%3D'icon']%20|%20/html/head/link[@rel%3D'ICON']%20|%20/html/head/link[@rel%3D'shortcut%20icon']%20|%20/html/head/link[@rel%3D'SHORTCUT%20ICON']"&format=json&callback=grab
显示Feed网站图标Greasemonkey脚本使用的查询.
您可以在YQL控制台中编写查询,但是需要登录(顺便说一句,不要使用查询):
You can write queries in YQL console, but it requires to login (btw, using queries don't):
http://developer.yahoo.com/yql/console/#h=select%20*%20from%20html%20where%20url%3D%22http%3A//bbc.co.uk/%22and%20xpath%3D%22/html/head/link%5B@rel%3D%27icon%27%5D%20%7C%20/html/head/link%5B@rel%3D%27ICON%27%5D%20%7C%20/html/head/link%5B@rel%3D%27shortcut%20icon%27%5D%20%7C%20/html/head/link%5B@rel%3D%27SHORTCUT%20ICON%27%5D%22
如果存在favicon,但不位于domain.com/favicon.ico
It is better than http://www.google.com/s2/favicons?domain=www.domain.com
, in case favicon exists, but doesn't located in domain.com/favicon.ico
这篇关于用JS获取网站的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!