Facebook SDK method
Since you need to check if the user has access to facebook you could try to initialize the the Facebook SDK and base your logic on that
According to documentation window.fbAsyncInit
function is called on a successful initialization of the SDK, so you might achieve your effect with something like this:
var campaignLink = "http://www.oursite.com/campaign";
window.fbAsyncInit = function() {
// facebook sdk initialized, change link
campaignLink = "http://www.facebook.com/example";
}
Please note that this is all theoretical and untested, you might need to read more here
https://developers.facebook.com/docs/reference/javascript/
Favicon method
This function tries to load the favicon.ico file of the supplied URL and takes it as an indicator on whether the site is accessible (by the user) or not. It assumes that a site has a favicon, but you could easily change that to another image which you know exists.. (example the 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";
}
Usage would 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)
}
})