1isSiteOnline("http://www.facebook.com",function(found){
2 if(found) {
3 // site is online
4 }
5 else {
6 // site is offline (or favicon not found, or server is too slow)
7 }
8})
9
1function isSiteOnline(url,callback) {
2 // try to load favicon
3 var timer = setTimeout(function(){
4 // timeout after 5 seconds
5 callback(false);
6 },5000)
7
8 var img = document.createElement("img");
9 img.onload = function() {
10 clearTimeout(timer);
11 callback(true);
12 }
13
14 img.onerror = function() {
15 clearTimeout(timer);
16 callback(false);
17 }
18
19 img.src = url+"/favicon.ico";
20}
21