getIcon

根据URL自动获取网页的favicon.ico图标,使你在网页开发中变的更方便。

使用方法

要获取一个favicon.ico 你可以链接到...

http://ico.ylsnuha.com/[URL]

注意网址中包含协议(http或https)。 例如...

http://ico.ylsnuha.com/http://www.google.com

以下是一个标准的<img> 标签...

<img src="http://ico.ylsnuha.com/http://www.google.com" alt="Google" width="16" height="16" />

默认图标

如果指定的域名无法获取图标,那可以指定一个默认图标...

http://ico.ylsnuha.com/http://www.google.com?defaulticon=http://en.wikipedia.org/favicon.ico

也可以定义defaulticon为以下4种:

De-cache

您可以从缓存中调用由一个图标/decache/?domain=[domain]例如:/decache/?domain=http://www.google.com.

JQuery方法添加图标

你可以使用JS为连接动态加载图标,这用不用编辑原始连接的代码

如果你没有载入JQuery库的话请先载入,已经有的跳过。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

插入一下JS,注意 #links a请根据自己的连接表标签做修改

<script type="text/javascript">

jQuery(document).ready(function($){

$("#links a").each(function(){

$(this).prepend("<img src=http://ico.ylsnuha.com/"+this.href.replace(/^(http:\/\/[^\/]+).*$/,'$1')+" style='float:left;padding:5px;width:16px;height:16px;'>")})});

</script>

事例