![](/img/trans.png)
[英]How to get favicon icon/ Apple-touch icon and title of a web page using Javascript or Jquery?
[英]How to get the apple touch icon from a site and if it doesn't exist then show favicon?
我想从网站上获取苹果触摸图标(据我了解, 大多数网站的图标都存储在website.com/apple-touch-icon.png
),并且是否有404或图片不存在然后使用Google网站图标抓取器( https://plus.google.com/_/favicon?domain_url=google.com
)显示网站的网站图标。
js / jquery有可能吗?
您可以将图像的网址设置为触摸图标网址,然后使用onerror
事件将其更改为收藏图标网址。
function getImage(url) {
image.src = url + "/apple-touch-icon.png";
image.onerror = function() {
image.src = "https://plus.google.com/_/favicon?domain_url=" + url;
}
}
演示 (记住在输入框中的网址前加上http://)
但是,某些网站使用的网址不是“ apple-touch-icon.png”,因此,您可能需要使用多个错误功能才能始终获得apple touch图标。
另外,某些网站(例如google)会为不存在的图片返回1px x 1px的图片,这意味着该图片无法正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.