或者能不能通过加载某个网页自动检查是否加载成功?
谢谢了

解决方案 »

  1.   

    可以的,用XMLHTTP请求某个门户站点,如果返回400,则大概可以说明网络有问题!
    原来51里有一个检测网卡状态的,你可以去搜索一下!
      

  2.   

    谢谢啊,说实话,我javascript很菜
    能不能给写一小段code示例,谢谢了
      

  3.   

    <!-----试一试,看看这个怎么样---><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title> New Document </title>
    <meta name="Generator" content="EditPlus">
    <meta name="Author" content="">
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    </head>
    <script language="javascript">
    function chkconnectionStatus(url)
    {
    this.ret=false; this.objXml=new ActiveXObject("Msxml2.XMLHTTP.5.0"); 

    this.objXml.open("post",url,false);
    this.objXml.onreadystatechange=function (){


    //alert(this.objXml.readyState); if(this.objXml.readyState==4)
    {
    //alert(this.objXml.status); if(this.objXml.status==200)
    {
    this.ret=true; }else
    {
    this.ret=false;
    return;
    }
    }
    }
    this.objXml.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
    try{
    this.objXml.send('');
    }catch(e)
    {
    this.ret=false;
    }
    return this.ret;
    } function chkit()
    {
    if(txturl.value=='')
    {
    alert('请输入一个测试的网站地址');
    txturl.focus();
    return ;
    }
    if(chkconnectionStatus(txturl.value))
    {
    txtstatus.innerHTML='<font color="blue">可以连接</font>';
    }else
    {
    txtstatus.innerHTML='<font color="red">无法连接!请确定您输入的地址是否存在或网络是否连通!</font>';
    }
    }
    </script>
    <body>
    <input type="text" id="txturl" value="http://www.163.com" />
    <button onclick="javascript:chkit();">test</button><span id="txtstatus"></span>
    </body>
    </html>
      

  4.   

    先谢谢楼上的
    这个实现用了activeX,因为我要在firefox上用
    还有其他方法吗?
    谢谢
      

  5.   

    XMLHTTP在FF里也可以用的,如下:
    // Initializevar Try = {
    these: function(){
    var returnValue;
    for(var i=0; i<arguments.length; i++){
    var lambda = arguments[i];
    try{
    returnValue = lambda();
    break;
    }catch(e){}
    }
    return returnValue;
    }
    }function ajaxInitRV(){
    return Try.these(
    function() {return new ActiveXObject('MSXML2.XMLHttp.6.0')},
    function() {return new ActiveXObject('MSXML2.XMLHttp.3.0')},
    function() {return new XMLHttpRequest()},
    function() {return new ActiveXObject('MSXML2.XMLHttp.5.0')},
    function() {return new ActiveXObject('MSXML2.XMLHttp.4.0')},
    function() {return new ActiveXObject('Msxml2.XMLHTTP')},
    function() {return new ActiveXObject('MSXML.XMLHttp')},
    function() {return new ActiveXObject('Microsoft.XMLHTTP')}
    ) || null;
    }
      

  6.   

    muxrwc说的对,用XMLHTTP只能在服务端执行了,用ASP文件试试。
      

  7.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>检测网络</title>
    <script type="text/javascript">
    var ising = function () {
    var wc = window.ActiveXObject ? new window.ActiveXObject("Microsoft.XMLHTTP") : new window.XMLHttpRequest,
    IE = /MSIE/.test(window.navigator.userAgent), returnValue;
    wc.open("get", "wc.asp", false);

    if (IE) {
    wc.onreadystatechange = function () {
    if (wc.readyState == 4 && wc.status == 200) {
    returnValue = wc.responseText;
    }
    };
    wc.send(null);
    } else {
    wc.send(null);
    returnValue = responseText;
    }
    return eval(returnValue.toLowerCase());
    };
    alert(ising() ? "畅通无阻" : "一塌糊涂");
    </script>
    </head>
    <body>
    </body>
    </html>
      

  8.   

    wc.asp
    <%
    Sub show
    Dim ajax
    Set ajax = Server.CreateObject("Microsoft.XMLHTTP")
    ajax.Open "Get", "http://www.baidu.com/", False
    ajax.Send
    Response.Write ajax.status = 200
    Set ajax = Nothing
    End Sub : show
    %>
      

  9.   

    没有搞懂,我主要是要用在firefox上啊