Der einfachste Weg, das Website -Symbol zu erhalten, besteht darin, sie über Website/favicon.ico zu erhalten. Da viele Websites Favicon auf der Seite einrichten, ist diese Methode in vielen Situationen nicht verfügbar.
Ein besserer Weg ist es, dies durch die von Google bereitgestellten Dienste zu erreichen:
http://www.google.com/s2/favicons?domain=http://www.baidu.com
Code:
Die Codekopie lautet wie folgt:
<! docType html>
<html>
<kopf>
<meta charset = "utf-8">
<style type = "text/css">
#Input {
Höhe: 300px;
Polsterung: 10px 5px;
Zeilenhöhe: 20px;
Breite: 1000px;
}
#einreichen {
Höhe: 30px;
Text-Align: Mitte;
Farbe: #ffffff;
Zeilenhöhe: 30px;
Breite: 80px;
Hintergrundfarbe: Blau;
Rand: 20px;
}
#Ergebnis {
Rand: 20px;
}
#Result li {
Höhe: 40px;
Zeilenhöhe: 40px;
float: links;
Rand: 10px 14px;
}
</style>
</head>
<body>
<textArea id = "Eingabe" Placeholder = "Geben Sie mehrere URLs mit Speicherintervallen ein"> </textArea>
<div id = "subieren"> icon </div>
<ul id = "result">
</ul>
<script type = "text/javaScript">
var input = document.getElementById ("input");
var subjekt = document.getElementById ("subieren");
var result = document.getElementById ("Ergebnis");
var val;
Funktion trim (str) {
var whitespace = '/n/r/t/f/x0b/xa0/u2005/u2002/u2003/u2004/u2005/u2006/u2007/u2008/u2009/u200a/u200b/u2028/u2029/u3000' '' ';
für (var i = 0, len = str.length; i <len; i ++) {
if (whitespace.indexof (str.charat (i)) === -1) {
str = str.substring (i);
brechen;
}
}
für (i = str.length-1; i> = 0; i--) {
if (whitespace.indexof (str.charat (i)) === -1) {
str = str.substring (0, i + 1);
brechen;
}
}
whitespace.indexof (str.charat (0)) === -1? str: '';
}
Funktion getFaviconurl (url) {
var prohost;
proHost = url.match (/([^: //?#]+: ////)? ([^//@:]+)/i);
prohost = prohost? Prohost: [True, "http: //", document.location.hostname];
// die URL vervollständige
if (! prohost [1]) {
prohost [1] = "http: //";
}
// Crawl ICO
return "http://www.google.com/s2/favicons?domain=" + prohost [1] + prohost [2];
}
subine.onclick = function () {
val = input.Value;
if (! val) alarm ("Eingabe ist leer!");
val = val.split ("");
Val.foreach (Funktion (Element) {
item = trim (item);
if (! item) return;
result.innerHtml + = "<li>" + item + "<img src = '" + getFaviconurl (Element) + "'> </li>";
});
};
</script>
</body>
</html>
Quellcode herunterladen