当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - check if facebook is blocked

问题描述:

I am using the facebook registration plugin, but certain workplaces now ban facebook (such as mine). I need to quickly determine if this is the case and show the alternative signup instead. I have read all the previous questions regarding this such as this one and the solution proposed seems pretty simple (load an image from facebook and use onerror to run any scripts you want when facebook is unavailable).

My problem with this is, when I test it at work, it takes 45 seconds before running the onerror script (it loads the rest of the page and says "Sending Request"). By that time, the user will have clicked the signup button and been sent to an error page (since facebook won't load).

Are there any ways of speeding up the process or another method to check if the user can access facebook?

网友答案:

You could asume that if it takes more then 2-3 seconds, the site isn't available. So either let the event run, or draw assumptions if it hasn't been loaded after a certain amount of times. It's reliable since facebook rarely takes more then a second to load stuff.

网友答案:

Schedule a timed event that reports "Facebook blocked" after just a few seconds. Have your image request cancel the timer if it returns successfully.

分享给朋友:
您可能感兴趣的文章:
随机阅读: