6

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.

Community
  • 1
  • 1
Doyle
  • 295
  • 2
  • 8
  • The favicon.ico isn't a safe bet. I can get the favicon of blocked websites at work. http://www.websense.com/content/home.aspx is the content blocker. – Robert Sep 28 '10 at 01:04
  • Do you have any suggestions Robert? Or does it come down to, being different everywhere? – Doyle Sep 28 '10 at 01:08
  • My suggestion would be to scrap the idea of trying to detect if it's blocking as there isn't really a foolproof way. – Robert Sep 28 '10 at 01:29
  • That just seems like a bit of a cop out though. In my opinion (and my clients) it's worth doing, even if it only works, to present a more profession site, for a selection of users. Thanks for your input though. – Doyle Sep 28 '10 at 01:34

2 Answers2

2

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
  • 69,683
  • 7
  • 133
  • 150
  • So you don't think the image height check is valid if the image has loaded? – Doyle Sep 28 '10 at 01:03
  • No, it isn't. As per my comment I can get the `favicon.ico`, scripts etc just fine. My company only blocks pages. – Robert Sep 28 '10 at 01:07
  • 1
    If the proxy serves up its own favicon at 16x16 it would give a false positive. – Dagg Nabbit Sep 28 '10 at 01:07
  • 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 Sep 28 '10 at 01:08
  • Yeah, I specifically wanted to avoid a file that might change. – Doyle Sep 28 '10 at 01:11
  • Would checking the height be more robust than leaving it as is? Even if it is still not a fool-proof method. – Doyle Sep 28 '10 at 01:17
  • 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 Sep 28 '10 at 01:21
  • 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 Sep 28 '10 at 01:27
  • 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 Sep 28 '10 at 01:41
  • 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 Sep 30 '10 at 01:32
  • Sure, if they all agree on a standard, it's possible. But getting them to agree is the hard part. :) – casablanca Sep 30 '10 at 03:36
0

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

Detecting if YouTube is blocked by company / ISP

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

Community
  • 1
  • 1
Dr.Molle
  • 116,463
  • 16
  • 195
  • 201