Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I test if a user viewing my website can not see some content, and how can I make sure my test works?

Tags:

javascript

I'm using code similar to below:

var image = new Image();
image.src = "http://youtube.com/favicon.ico";
image.onload = function(){
// The user can access youtube
};
image.onerror = function(){
// The user can't access youtube
};

Which I found here: Detecting if YouTube is blocked by company / ISP

To test if a user has access to youtube/facebook/twiter, so when I try to embed a video, or a like button. I know if the user can see it. At my workplace whenever I go to a website that uses a like/tweet button etc, I see a small portion of an ugly page telling me that the content is blocked on our network. I don't want the people visiting my site to see this.

The above code works fine for me on my network. But what methods can I use to test it to make sure it will work for everyone, and if it doesn't what code would, as every workplace/network blocks content differently.

Thanks for any answers.

like image 706
Doyle Avatar asked Sep 28 '10 00:09

Doyle


1 Answers

What you're doing is the best you can get. You answered yourself partly when you mentioned that "every workplace/network blocks content differently". For all you know, the mediating proxy could return a valid webpage or image when you try to request a blocked resource. This wouldn't be an error condition but obviously it also wouldn't be the content that you were expecting. There is no "sure" way to tell if the returned content is correct or not.

like image 75
casablanca Avatar answered Nov 02 '22 16:11

casablanca