Get the website icon, commonly used the easiest way is through Website/favicon.ico to get, but because many sites are in the page set Favicon, so this method many situations are not available.
The better way to do this is through services provided by Google:
Http://www.google.com/s2/favicons?domain=http://www.baidu.com
Code:
Copy Code code as follows:
<!doctype html>
<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>
<body>
<textarea id= "Input" placeholder= "Enter multiple URLs at space intervals" ></textarea>
<div id= "Submit" > Get 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];
Full URL
if (!prohost[1]) {
Prohost[1] = "http://";
}
Grab ico
Return "http://www.google.com/s2/favicons?domain=" + prohost[1] + prohost[2];
}
Submit.onclick = function () {
val = input.value;
if (!val) alert ("Input is empty!") ");
val = Val.split ("");
Val.foreach (function (item) {
Item = Trim (item);
if (!item) return;
result.innerhtml + + "<li>" + Item + "</li>";
});
};
</script>
</body>
Source code Download