How to get the website icon What are the possible ways _javascript skills

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.