Facebook SDK Method
Since you need to check if the user has access to facebook, you can try to initialize the Facebook SDK and base your logic on this
According to the documentation of window.fbAsyncInit function is called when the SDK is successfully initialized, so you can achieve your effect something like this:
var campaignLink = "http://www.oursite.com/campaign"; window.fbAsyncInit = function() {
Please note that this is all theoretical and untested, you may need to read here
https://developers.facebook.com/docs/reference/javascript/
Favicon method
This function attempts to load the favicon.ico file of the attached URL and takes it as an indicator of whether the site is accessible (by the user) or not. The site is supposed to have an icon, but you can easily change it to another image that you know exists. (E.g. facebook logo)
function isSiteOnline(url,callback) { // try to load favicon var timer = setTimeout(function(){ // timeout after 5 seconds callback(false); },5000) var img = document.createElement("img"); img.onload = function() { clearTimeout(timer); callback(true); } img.onerror = function() { clearTimeout(timer); callback(false); } img.src = url+"/favicon.ico"; }
Use will be
isSiteOnline("http://www.facebook.com",function(found){ if(found) { // site is online } else { // site is offline (or favicon not found, or server is too slow) } })
source share