[转]通过HTML网页检测网站是否能够访问,如果不能访问则报警。

未经验证,收藏,防丢失

<!--1 test.htm文件开始-->

<html>
<head>
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<title>网站测试页面</title>
</head>

<body>
<table width="100%"  cellspacing="0" cellpadding="0">
  <tr>
    <td align="center"><span id="ts">网站正常......</span><br><span id="sj"></span></td>
  </tr>
</table>

<SCRIPT language=javascript>

document.writeln('<div style="position:absolute;top:-100;left:-100;" id="LiveGoalMusic" name="LiveGoalMusic"></div>');
var xmlDocTopic = null;

//Possible prefixes ActiveX strings for DOM DOcument
var ARR_ACTIVEX = ["MSXML4.DOMDocument", "MSXML3.DOMDocument", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XmlDom"];

//When the proper prefix is found, store it here
var STR_ACTIVEX = "";
var bXMLCtlFound = false;
   
for(var i=0; i < ARR_ACTIVEX.length && !bXMLCtlFound; i++){
 try{
  xmlDocTopic = new ActiveXObject(ARR_ACTIVEX[i]);

  STR_ACTIVEX = ARR_ACTIVEX[i];
  bXMLCtlFound = true;             

 }
 catch(objException){
  xmlDocTopic = null;
 }
}

if (!bXMLCtlFound){
 throw "No DOM DOcument found on your computer.";
}


var oldUpdateTime = "";
var lastUpdateTime;
var checktime=60000;//超时时间,单位:毫秒
var refuTime=30000;//刷新页面时间,单位:毫秒
my1=OpenXML();
my2=check();

sj.innerHTML = new Date();


function OpenXML(){
        xmlDocTopic.load("time.xml");
 xmlDocTopic.onreadystatechange = xmlDocTopiconreadystatechange;
 my1=window.setTimeout("OpenXML()", refuTime);

}


 
function check(){

 if (oldUpdateTime == lastUpdateTime && oldUpdateTime != ""){
  if(my1 != null) clearTimeout(my1);
  if(my2 != null) clearTimeout(my2);
  ts.innerHTML = '网络存在问题,请检查您的网络连接后刷新页面。<br>如果还不能正常显示,请通知xxxxxxxxxx<br><input type="submit" name="Submit" value="刷新" οnclick="location.reload(true);">';
  playSWFGoal(); 
//  if (confirm("由于网络问题,你已经和服务器断开连接超过 "+(checktime/1000/60)+" 分钟,是否要重新连接?/n/n 如果得新连接后无法查看页面请通知管理员:xxxxxxxxxxxxx"))
//  {
//   location.reload(true);
//   }
    }
 oldUpdateTime = lastUpdateTime;
 my2=window.setTimeout("check()", checktime);

}

function xmlDocTopiconreadystatechange(){
 if (xmlDocTopic.readyState != 4) return;
    if (xmlDocTopic.xml == "")return;
//    alert(xmlDocTopic.readyState);
 d = new Date();
 lastUpdateTime = FormatNumber(d.getHours()) + ":" + FormatNumber(d.getMinutes());
        sj.innerHTML = d;
}


function FormatNumber(n){
 if (n < 10)
  return ("0" + n);
 else
  return n;
}

function playSWFGoal(){
 try{
  LiveGoalMusic.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="0" height="0"><param name="movie" value="http://www.gooooal.com/live/goal.swf"><param name="quality" value="high"><param name="wmode" value="transparent"></object>';
  window.setTimeout("playSWFGoal()", 10000);
 }
 catch(e){}
}
</script>
</body>
</html>


<!--1 test.htm文件结束-->

<!--2 time.xml文件开始-->

<?xml version='1.0' encoding='GB2312'?>
<Data>
 <M>
  <G>36#1#2000</G>
 </M>
</Data>

<!--2 time.xml文件结束-->

将以上两个文件上传到网站

以这样的网址打开http://www.xxx.xxx.xx/test.htm (www.xxx.xxx.xx为你的网址) 并且打开音箱(该例子以http://www.gooooal.com/live/goal.swf为报警声)

如果警报声响则说明网络正常但你要检测的网站不能访问,

如果提交出错但没警报声则说明你的网络链接有问题。

如需转载请声明出处:http://blog.csdn.net/stbrine/


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/stbrine/archive/2006/06/05/774255.aspx

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值