0

I am using social plugin in website like Facebook,twitter,googleplus
How can I check these social website are alive before using social plugin code.

Actually I am facing problem when any social website goes offline then website page gets more time to load where I used these social plugin.

I used this code but it throws exception and consume lot of time if website is offline

HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("http://www.stackoverflow.com");
httpReq.AllowAutoRedirect = false;

HttpWebResponse httpRes = (HttpWebResponse)httpReq.GetResponse();

if (httpRes.StatusCode==HttpStatusCode.NotFound) 
{
   // Code for NotFound resources goes here.
}

Any idea how overcome this problem?

Shoaib Ijaz
  • 5,347
  • 12
  • 56
  • 84

1 Answers1

2

What specifically are you trying to do if they are online? If so you can using window.load() on the client side, fire off the events and in turn extract whatever data you need from them if available. One idea is to check your code on window.load


$(window).load(function () {
  // run code to check if live
});

For the actual code itself to see if a site is up, see this post Javascript: Check if server is online?

Community
  • 1
  • 1
Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71
  • :it also creating same issue page is just loading.if website is online then response is quick. – Shoaib Ijaz Sep 20 '12 at 20:48
  • I didn't follow what you said? – Adam Tuliper Sep 20 '12 at 21:44
  • I want quick response for check the website is alive or not.But when i used these function it consume lot of time for response.. – Shoaib Ijaz Sep 21 '12 at 18:23
  • Then set the timeout on an XmlHttpRequest object, but if the destination site is slow you would have a false positive. You cannot check on the client side if they are immediately offline that I'm aware of (you have no access to network connection state) you simply try a connection and let it fail via an img tag or control the xmlhttprequest object timeout ala http://stackoverflow.com/questions/1391453/air-xmlhttprequest-time-out-if-remote-server-is-offline – Adam Tuliper Sep 24 '12 at 15:21