日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

如何获取网站icon

發布時間:2024/1/17 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何获取网站icon 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

獲取網站icon,常用最簡單的方法就是通過website/favicon.ico來獲取,不過由于很多網站都是在頁面里面設置favicon(<link?rel="shortcut icon"??href="http://example.com/favicon.ico"?/>),所以此方法很多情況都不可用。

更好的辦法是通過google提供的服務來實現:http://www.google.com/s2/favicons?domain=http://www.baidu.com

代碼:

<!doctype html> <html><head><meta charset="utf-8"><style type="text/css">#input {height: 300px;padding: 10px 5px;line-height: 20px;width: 1000px;}#submit {height: 30px;text-align: center;color: #ffffff;line-height: 30px;width: 80px;background-color: blue;margin-top: 20px;}#result {margin-top: 20px;}#result li {height: 40px;line-height: 40px;float: left;margin: 10px 14px;}</style> </head><body><textarea id="input" placeholder="輸入多個網址以空格間隔"></textarea><div id="submit">獲取icon</div><ul id="result"></ul><script type="text/javascript">var input = document.getElementById("input");var submit = document.getElementById("submit");var result = document.getElementById("result");var val;function trim(str) {var whitespace = ' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';for (var i = 0, len = str.length; i < len; i++) {if (whitespace.indexOf(str.charAt(i)) === -1) {str = str.substring(i);break;}}for (i = str.length - 1; i >= 0; i--) {if (whitespace.indexOf(str.charAt(i)) === -1) {str = str.substring(0, i + 1);break;}}return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';}function getFavIconUrl(url) {var prohost;prohost = url.match(/([^:\/?#]+:\/\/)?([^\/@:]+)/i);prohost = prohost ? prohost : [true, "http://", document.location.hostname];//補全urlif (!prohost[1]) {prohost[1] = "http://";}//抓取icoreturn "http://www.google.com/s2/favicons?domain=" + prohost[1] + prohost[2];}submit.onclick = function() {val = input.value;if (!val) alert("輸入為空!");val = val.split(" ");val.forEach(function(item) {item = trim(item);if (!item) return;result.innerHTML += "<li>" + item + "<img src='" + getFavIconUrl(item) + "'></li>";});};</script> </body></html>

?

源代碼下載:http://files.cnblogs.com/shinnyChen/getIcon.rar

?

后記:

對于國內的網站,也可以使用360的服務:

http://cdn.website.h.qhimg.com/index.php?domain=www.baidu.com

轉載于:https://www.cnblogs.com/shinnyChen/p/3722562.html

總結

以上是生活随笔為你收集整理的如何获取网站icon的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。