Q: How to use pure JavaScript to determine whether Facebook/Twitter is blocked? Some countries like China is blocking Facebook/Twitter. How to use JavaScript to check whether a website is not accessible?
update:
I am adding a "Share to Facebook" button on a web page. 50% of the visitors are from China and 50% are from outside of China.
For those China visitors, they would never see that Facebook button because it's blocked. I want to use $.hide() or $.empty() to remove the related HTML if I detected that Facebook is blocked. How can I do that?

A: You can check if loading the facebook SDK is blocked in china (//connect.facebook.net/en_UK/all.js)
If this is the case then you could do something like this:
  $.getScript('//connect.facebook.net/en_UK/all.js')
  .success(function(){
        // do something if facebook is available 
  });

You need to take care because you need to define a timeout if you want to make a callback for the fail case. I need to check the correct settings later, but currently i don't have time to.
EDIT
Based on the comment of funkybro it would be better to do a JSONP request. Loading the API would inject a butch of code you probably don't need.
So just request e.g.:
$.getJSON('https://graph.facebook.com/feed?callback=?')
.success(function(){
     // do something if facebook is available 
});

The request will include a failure code because you don't provide at graph node, but knowing that you get an error message from facebook means that it is reachable for the client.

A: Use jQuery.get like this:
$.get("http://facebook.com").fail(function() {
    $(...).hide()
}).done(function() {
    $(...).show()
})

Note that this is a cross-site request that will fail for security reasons unless you disable that browser feature.
If that's not possible for you, I suggest you use GeoIP or similar technologies to determine the users origin.
