使用通用选项添加网站图标 [英] Adding favicons with generic option

查看:107
本文介绍了使用通用选项添加网站图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用favicon.ico将图标添加到我的网站.

I'd like to add favicons to my site using favicon.ico.

但是,如果网站不提供图标,我想加载一个通用图标.

however I want to load a generic icon if the site does not provide one.

如何测试图标图标的外观,如果不存在图标,请操作DOM指向服务器上的通用图标图标.

How can I test for the presense of a favicon and if one is not present manipulate the DOM to point to a generic favicon on the server.

推荐答案

您可以使用一些JavaScript.适应西装...

You could use some JavaScript. Adapt to suit...

var img = document.getElementsByTagName('img')[0],
    favicon = new Image;

favicon.onerror = function() {
    img.src = 'http://some-other-url.com/favicon.ico';
}

favicon.src = 'http://example.com/favicon.ico';

这篇关于使用通用选项添加网站图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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