javascript - Test if URL is accessible from web browser i.e. make sure not blocked by Proxy server -


i serving website mywebsite.com. host images on flickr images loaded in user's browser via requests flickr. many of websites users access mywebsite.com corporate networks, block access flickr.com. means users annoying blank placeholders instead of images. same problem facebook button. makes site unattractive such users.

is there way can run client side script check if flickr.com, facebook.com, etc. accessible. if not change href attribute of image load alternate source, or replace standard image explaining network blocking access. remove facebook button.

i thought xml http request trick, i'd hit cross domain issues think. guess set proxy serve images, don't want that; idea of flickr takes bandwidth hit.

tldr: how determine if flickr.com accessible user's browser, using client side technology.

you try this...

var image = new image();  image.onerror = function() {     var images = document                  .getelementbyid('flicker-images')                  .getelementsbytagname('img');     (var = 0, imageslength = images.length; < imageslength; i++) {         images[i].src = 'images/flickr_is_blocked.gif';    }  };  image.src = 'http://flickr.com/favicon.ico'; 

hacky, seems work. relies favicon.ico 404ing means main site is.

jsfiddle.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -