如何检索网站的收藏夹图标? [英] How can I retrieve the favicon of a website?

查看:54
本文介绍了如何检索网站的收藏夹图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的网站上列出特色网站,我认为荣誉和使用他们的网站图标会很酷.在JSP或XSLT中,如何从域中获取任意URL?我可以关闭PHP或javascript,但是XSLT是首选方法.

I want to list featured websites on my website and I thought it would be cool to honor and use their favicon. How do I get it from the domain for an arbitrary URL in either JSP or XSLT? I can fire off PHP or javascript, but XSLT is the preferred methodology.

推荐答案

要获取网站的收藏夹,您需要加载每个特色网站的索引HTML并检查以下各项之一:

To get the favicon of a website, you need to load the index HTML of each featured website and check for either of the following:

HTML:

<link rel="icon" type="image/vnd.microsoft.icon" href="http://example.com/image.ico">
<link rel="icon" type="image/png" href="http://example.com/image.png">
<link rel="icon" type="image/gif" href="http://example.com/image.gif">

XHTML:

<link rel="icon" type="image/vnd.microsoft.icon" href="/somepath/image.ico" />
<link rel="icon" type="image/png" href="/somepath/image.png" />
<link rel="icon" type="image/gif" href="/somepath/image.gif" />

Internet Explorer可能使用略有不同的格式:

Internet Explorer may use a slightly different format:

<link rel="SHORTCUT ICON" href="http://www.example.com/myicon.ico" />

还要注意,由于大多数Web浏览器不需要HTML链接来检索图标,因此,如果以上链接引用均未找到,则还应检查网站文档根目录中的favicon.ico.

Also note that since most web browsers do not require the HTML link to retrieve a favicon, you should also check for favicon.ico in the website's document root, if none of the above link references are found.

使用PHP,可以很容易地通过使用

With PHP, it is easy to get the HTML contents of a web page by using file_get_contents($url):

$url = 'http://www.exmaple.com';
$output = file_get_contents($url);

这篇关于如何检索网站的收藏夹图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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