[Project_owners] Online/Offline

HJ bugs4hj at yahoo.com
Fri Apr 14 11:29:22 EDT 2006


Brian King wrote:
> What is the best way for an extension to detect if a user is 
> online/offline? I'm not talking about, for example, the Work Offline 
> feature in Firefox, but rather about whether they have an internet 
> connection at the time a particular piece of code is executing.

What about something like:

var xmlRequest = new XMLHttpRequest();
xmlRequest.open("HEAD", aURL, true);
xmlRequest.onerror = function(aEvent)
{
   var request, status;

   try {
     request = aEvent.target;
     status = request.status;
   }
   catch(ex) {
     request = 
aEvent.target.channel.QueryInterface(Components.interfaces.nsIRequest);
     status = request.status;
   }
   if (status > ) {
     see: 
http://lxr.mozilla.org/seamonkey/source/netwerk/base/public/nsNetError.h
   }
   blablabla...
}
xmlRequest.onload = function() { do something }

/HJ


More information about the Project_owners mailing list