那个想用纯JS检测404错误的,来看看.不一定很准确

发表于:2007-06-30来源:作者:点击数: 标签:
span id=url1/spanbr span id=url2/span script language= Java Script function butt(){ tim=1 setInterval(tim++,100) b=1 autourl1=http://www.dev_club.com/club/bbs/bbsView.asp?boardid=1 autourl2=http://www.devclub.com/club/bbs/bbsView.asp?boardi
<span id=url1></span><br>
<span id=url2></span>
<script language="JavaScript">
    function butt(){
        tim=1
        setInterval("tim++",100)
        b=1
        autourl1="http://www.dev_club.com/club/bbs/bbsView.asp?boardid=1"
        autourl2="http://www.devclub.com/club/bbs/bbsView.asp?boardid=1"
        url1.innerHTML=" 测试连接:http://www.dev_club.com/club/bbs/bbsView.asp?boardid=1,测试中..... "
        url2.innerHTML=" 测试连接:http://www.devclub.com/club/bbs/bbsView.asp?boardid=1,测试中..... "
    }
    
    function auto(url){
        if(tim>20) {           @#这个20是关键.20代表2秒.我是假设2秒没反映就认为是连接错误
            document.all(url).innerHTML=" 链接超时 "
        }else{
            document.all(url).innerHTML=" "+tim/10+"秒 "
        }
        b++
    }
    
    function run(){
        document.write("<img src="+autourl1+"/"+Math.random()+" width=1 height=1 onerror=auto(@#url1@#)>")
        document.write("<img src="+autourl2+"/"+Math.random()+" width=1 height=1 onerror=auto(@#url2@#)>")
    }

    butt()
    run()
</script>

原文转自:http://www.ltesting.net