Hi everybody
my question is: is it possible to develope a function isConnected()
that returns a boolean (true if the user have network connection...)??
I know there is a function that updates network state every "n"
seconds but I don“t want that, I want a function that returns a
boolean with the actual network status.
Looks easy, I have tryed this:
var connected=false;//global variable initializated
function isConnected()
{
var resource_to_test = "resource.txt";
try{
var req=getXHR();
req.open('GET',resource_to_test);
req.onreadystatechange = function()
{
if (req.readyState == 4)
{
if (req.status == 200)
{
connected=true;//update
value
}
else
{
connected=false;//update value
}
}
};
req.send(null);
return connected;// return the boolean, always return false
(initializated vaule)...
}
but the variable "connected" is updated by onreadystatechange event
AFTER the function isConnected() returns the value.
Is there a wat to do that?
Does Gears provide another way to develope a boolean function that
updates network state?
Thanks!