我在我的页面上显示其他网站的图标。
大约一半的时间他们在这里:
hostname.com/favicon.ico
但另一半他们不在这里。例如,在我自己的网站中,我链接到我的 .ico 文件,如下所示。 FAVICON 只是路径的 PHP 定义。
<link rel="SHORTCUT ICON" href="<?php echo FAVICON ?>" />
如何使用 html 中的链接获取网站图标的 URL?
这是网站,你可以像这样进行谷歌搜索在其中输入您需要其网站图标的域。
http://www.google.com/s2/favicons?domain=domain
这是一种解决方案,但似乎比从路径读取 html 效率低。
我认为谷歌将“所有”图标缓存为.png格式并使它们可搜索 -
根据此 网站
I display favicon's from other sites on my page.
About half the time they are here:
hostname.com/favicon.ico
But the other half they are not. For ecample in my own site I link to my .ico file like this. FAVICON is just a PHP definition of the path.
<link rel="SHORTCUT ICON" href="<?php echo FAVICON ?>" />
How do I get the URL of a site's favicon using the the link in the html?
This is site sais you can do a google search like this where you enter the domain you need the favicon for.
http://www.google.com/s2/favicons?domain=domain
Which is one solution but seems less efficient than just reading the html from the path.
I think google cached "ALL" icons into .png format and made them searchable -
per this site
发布评论
评论(2)
使用 Ajax 和代理页面加载页面。对于 Ajax:
以及代理页面(您可能需要添加一些安全性):
Google“Ajax”,您会发现很多有关如何执行此类操作的信息。
您需要代理页面的原因是,浏览器不允许来自 JavaScript 的 Ajax 请求跨域,除非目标允许,而目标必须明确这样做。这是出于安全原因,因为 JavaScript 可能会恶意冒充用户。因此,您可以使用服务器端脚本代理内容并避免此类问题。
Load the page using Ajax and a proxy page. For the Ajax:
And the proxy page (you'll probably want to add some security):
Google "Ajax" and you'll find lots of information on how to do that sort of thing.
The reason you need to proxy the page is that browsers don't allow Ajax requests from JavaScript to go across domains unless the target allows it, which it must do explicitly. This is for security reasons, since the JavaScript could be maliciously impersonating the user. So instead, you proxy the content using a server-side script and avoid such problems.
解析 HTML 很麻烦 - 你可能想使用这样的库: http:// www.controlstyle.com/articles/programming/text/php-favicon/ 或让 google 为您完成:http://www.google.com/s2/favicons?domain=domain(效率更高 - 您不必解析服务器上的所有 HTML,它只是其中一个标签)。如果您想在您的服务器上使用类似谷歌的功能,请查看上面的链接。
Parsing HTML is nasty - you probably want to use a library like: http://www.controlstyle.com/articles/programming/text/php-favicon/ or let google do it for you: http://www.google.com/s2/favicons?domain=domain (much more efficient - you don't have to parse all the HTML on your server, and it's just one tag). If you want something like google's functionality on your server, check out the link above.