Gears 判断网页状态
Gears 判断网页状态
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>取网页当前状态!</title>
<script type="text/javascript" src="JS/gears_init.js"></script>
<script type="text/javascript" src="JS/sample.js"></script>
<script language="javascript" type="text/javascript">
//取网页当前状态
var PageStatus=true;
function GetPageOnLineStatus()
{
var request = google.gears.factory.create('beta.httprequest', '1.0');
if (request)
{
var tmpUrl="4.html?now=" + new Date().getTime();//4.html是个空网页
request.open("GET", tmpUrl, true);
request.onreadystatechange=function()
{
try
{
if(request.readyState==4)
{
if(request.status==200)
{
SetPageStatus("OnLine");
}
else
{
SetPageStatus("OffLine");
}
}
}
catch(EX)
{
SetPageStatus("OffLine");
}
};
request.send(null);
}
}
function SetPageStatus(statusStr)
{
var Elmstatus=getElementById("status");
if(statusStr=="OnLine")
{
Elmstatus.innerHTML += '<span>'+statusStr+'</span><br/>';
PageStatus=true;
setTimeout("GetPageOnLineStatus()",1000);
}
else
{
Elmstatus.innerHTML += '<span>'+statusStr+'</span><br/>';
PageStatus=false;
setTimeout("GetPageOnLineStatus()",1000);
}
}
function Test()
{
if(PageStatus)
{
alert("连接");
}
else
{
alert("断开");
}
}
</script>
</head>
<body onload="GetPageOnLineStatus()">
<form action="Index.html">
Get Page Status:
<input id="btn" type="button" onclick="Test()" value="确定"><br />
<div id="status">
</div>
</form>
</body>
</html>