tags:

views:

61

answers:

2

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: http://stackoverflow.com/questions/286021/detecting-if-youtube-is-blocked-by-company-isp/1804634#1804634

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.

A: 

Hi,

if the image is loaded, you can check the width/height of the loaded image against the original size of the requested image.(Should be 16/16 for http://youtube.com/favicon.ico )

This is also described in the linked Topic

http://stackoverflow.com/questions/286021/detecting-if-youtube-is-blocked-by-company-isp/286066#286066

I dont think that the blocking application will request the original ressource to lookup, what size it will have.

Dr.Molle
+2  A: 

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.

casablanca
So you don't think the image height check is valid if the image has loaded?
Doyle
No, it isn't. As per my comment I can get the `favicon.ico`, scripts etc just fine. My company only blocks pages.
Robert
If the proxy serves up its own favicon at 16x16 it would give a false positive.
no
At least not with a common filename such as `favicon.ico` that exists on many servers. If you could find some other file unique to YouTube, you *might* have some success, but then you risk failure when YouTube changes its file structure.
casablanca
Yeah, I specifically wanted to avoid a file that might change.
Doyle
Would checking the height be more robust than leaving it as is? Even if it is still not a fool-proof method.
Doyle
As far as I know, all favicons are 16x16, so checking dimensions wouldn't help either. In the end, I don't think it's worth the time to check for content access and hide stuff.
casablanca
Yes, but it would work in the case where a blocker returns a banner image saying 'content blocked' when the favicon is access rather than a favicon at all?I think it is worth doing, and I wouldn't be surprised if as the use of things such as like/tweet buttons increases, a fool-proof method it introduced to test if it is blocked. It's quite unprofessional in my opinion to have a site trying to display a youtube video, but instead displays a content blocked error to anyone who has it blocked, whereas it could simply be swapped to a gif or text block as a less functional alternative.
Doyle
Such a "fool-proof method" cannot exist because there is no way for a computer to tell if what you get is a "content blocked" image or the actual image. If only a small percent of your audience is blocked, it really doesn't matter they see a "blocked" message. If, on the other hand, you expect most people to be blocked, then adding a video/button doesn't make sense in the first place.
casablanca
It can exist, all it will take is for those that block content to define a standard for how they output blocked content messages/images/reports. They may not want to, but I think it is possible, and wouldn't be surprised if there is more demand for it one day. But I'm content with my solution for now. Thanks to everyone for their help and comments.
Doyle
Sure, if they all agree on a standard, it's possible. But getting them to agree is the hard part. :)
casablanca