开发者

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

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 d开发者_开发知识库on'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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜