js有没有办法判断客户端机器是否可以连接互联网?有的话麻烦指教!

解决方案 »

  1.   

    http://topic.csdn.net/u/20090902/17/b90f6280-05e7-4e55-bbaa-d0b747719cd3.html
      

  2.   

    我特别想知道你的js是写在web页面里的吗?如果是的,那机器能不能联网有什么关系呢?能联网你的页面才能访问,js才有机会跑起来,不需要判断!不能联网,你的页面都不能打开,谈不上判断什么!
      

  3.   

    用jquery写的<!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>
        <title>网路连接测试页面</title>
        <script type="text/javascript" src="jquery-1.4.2.js"></script>
        <script type="text/javascript">
            function NetPing() {
                $.ajax({
                    type: "GET",
                    cache: false,
                    url: "http://www.163.com/index.html", //设置你需要测试的网络IP 
                    data: "",
                    success: function () {
                        Done(1);
                    },
                    error: function () {
                        Done(0);
                    }
                });
            }        function Done(rel) {
                if (rel == 1) {
                    document.getElementById('Text1').value = "网络已连接";
                }
                else {
                    document.getElementById('Text1').value = "网络未连接";
                }
            }        function Button1_onclick() {
                NetPing();
            }
        </script>
    </head>
    <body>
        <input id="Button1" type="button" value="测试" onclick="return Button1_onclick()" />
        <input id="Text1" type="text" readonly="readonly" />
    </body>
    </html>