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.

4
  • The favicon.ico isn't a safe bet. I can get the favicon of blocked websites at work. websense.com/content/home.aspx is the content blocker.
    – Robert
    Sep 28, 2010 at 1:04
  • Do you have any suggestions Robert? Or does it come down to, being different everywhere?
    – Doyle
    Sep 28, 2010 at 1: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, 2010 at 1: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, 2010 at 1:34

2 Answers 2

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.

11
  • So you don't think the image height check is valid if the image has loaded?
    – Doyle
    Sep 28, 2010 at 1: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, 2010 at 1:07
  • 1
    If the proxy serves up its own favicon at 16x16 it would give a false positive. Sep 28, 2010 at 1: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, 2010 at 1:08
  • Yeah, I specifically wanted to avoid a file that might change.
    – Doyle
    Sep 28, 2010 at 1:11
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.