Answers for "how to check if website is down javascript"

0

how to check if website is down javascript

function isSiteOnline(url,callback) {
    // try to load favicon
    var timer = setTimeout(function(){
        // timeout after 5 seconds
        callback(false);
    },5000)

    var img = document.createElement("img");
    img.onload = function() {
        clearTimeout(timer);
        callback(true);
    }

    img.onerror = function() {
        clearTimeout(timer);
        callback(false);
    }

    img.src = url+"/favicon.ico";
}
Posted by: Guest on July-24-2021
0

how to check if website is down javascript

isSiteOnline("http://www.facebook.com",function(found){
    if(found) {
        // site is online
    }
    else {
        // site is offline (or favicon not found, or server is too slow)
    }
})
Posted by: Guest on July-24-2021

Code answers related to "how to check if website is down javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language