文章资讯 | 实用查询 | 桌面壁纸 | 网络电台 | 网址成语五笔字典 | 歇后语笑话软件 | 算命 | 周公解梦 | 生日密码 | 小游戏 | 许愿墙 | 天气留言
您现在的位置: 蓝派网 >> 文章中心 >> 网页制作 >> JavaScript >> 文章正文
站内文章搜索:           

让浏览者自动转向你的网站的最速分站

作者:佚名    文章来源:im286.com    更新时间 :2008-7-16 20:06:43
先给大家介绍一下原理:

我的主站是:
http://www.myelogo.com

现在有四个分站分别是:
http://www1.myelogo.com
http://www2.myelogo.com
http://www4.myelogo.com
http://www6.myelogo.com

我想在用户注册时,在主站http://www.myelogo.com注册完毕后[color=Red]自动转向对他来说速度最快的分站[/color],经过努力已经完成了这个功能的程序编写,程序采用javascript编写,简单易用。具体如下,如果大家需要的话修改一下参数c[color=Red]hildSite[/color]即可使用:

[code]
<script language='JavaScript'>
var childSite = new Array("http://www1.myelogo.com","http://www2.myelogo.com","http://www4.myelogo.com","http://www6.myelogo.com/");//把这里的www1.myelogo.com,www2.myelogo.com,www4.myelogo.com,www6.myelogo.com换成自己的分站即可使用                                                                                                       
</script>       
<div id="redirectwrap">
<h4>正在为您查找最快的注册分站,请耐心等待...</h4>
                       
<form name=SpeedTest>
<center>
<table border="0" cellspacing="0" height="100%" width="100%">
<tr>
<td colspan="1"  align="center" id="displarAera">

</td>
</tr>      
</table>
</center>
</form>
<p class="redirectfoot">Melogo.com (C) 版权所有</p>
</div>
               
<SCRIPT LANGUAGE=JavaScript>
//-------------------------------------------------------------------------------------------------------------------
var childParam= new Array(childSite.length);
var childParamB= new Array(childSite.length);
//-------------------------------------------------------------------------------------------------------------------
function inital()
{
        for(i=0;i<childSite.length;i++)
        {
                childParam[i]=Array(childSite[i],"speed"+i,0,0);
                childParamB[i]=0;
        }

}
//-------------------------------------------------------------------------------------------------------------------
function writeElement(theArray)
{
        var sstr="";
       
        for(i=0;i<theArray.length;i++)
        {
                sstr+= theArray[i][0] + " = " + "<input readonly type=text name='"+ theArray[i][1] +"' size=8 maxlength=4  style=\"border-width:0; font-size:10pt;color:#FF0000;font-family:Arial; font-weight:bold; background-color: #F7F7FF\"><br>\n";       
        }
        sstr+="<input readonly type=text name='show' size=50 maxlength=4  style=\"border-width:0; font-size:10pt;color:#FF0000;font-family:Arial; font-weight:bold; background-color: #F7F7FF; text-align: center\"><br>\n";       
        sstr+="<input readonly type=text name='gogo' size=50 maxlength=4  style=\"border-width:0; font-size:10pt;color:#FF0000;font-family:Arial; font-weight:bold; background-color: #F7F7FF; text-align: center\">";       
       
        window.displarAera.innerHTML = window.displarAera.innerHTML + sstr;
}
//-------------------------------------------------------------------------------------------------------------------
inital();
writeElement(childParam);
//-------------------------------------------------------------------------------------------------------------------
var timecount=1;
var interval=10;


sti=setInterval("autotime()",interval);

function autotime()
{
        if(timecount>2000)
        {
                for(b=0;b<childSite.length;b++)
                {
                        if(document.SpeedTest.elements["speed"+b].value=='测试中...')
                        {
                                document.SpeedTest.elements["speed"+b].value='1000'
                        }
                }
                clearInterval(sti);
                //alert("ok");
        }
        else
        {
                timecount++;
        }
}
//-------------------------------------------------------------------------------------------------------------------
function DoTest()
{
        for(i=0;i<childSite.length;i++)
        {
        childParam[i][2]=timecount;

        document.SpeedTest.elements[childParam[i][1]].value='测试中...';
        document.write("<img src='http://" + childParam[i][0] + "/-myelogo-.gif'width=1 height=1 onerror='DoCount("+i+",timecount,childParam["+i+"][2],\""+childParam[i][1]+"\");'>");
        }       
}
//-------------------------------------------------------------------------------------------------------------------
DoTest();
//-------------------------------------------------------------------------------------------------------------------
var haveGetSpeed=0;

function DoCount(i,start,end,elem)
{
var kkstr="";
var fast=2000;
var fastId=1000;
        timespace=start-end;
        if(timespace>2000)
        {
                eval('document.SpeedTest.elements[elem].value="1000"');
                childParam[i][3]=timespace/100;
        }
        else
        {
                var timestr=timespace/100;
                eval('document.SpeedTest.elements[elem].value=timestr');
                childParam[i][3]=timespace/100;
        }
       
        haveGetSpeed++;//判断是否测试完毕
       
        if(haveGetSpeed==childSite.length)
        {
                  for(z=0;z<childSite.length;z++)
                        {
                                  if(fast>childParam[z][3])
                                  {
                                          fast=childParam[z][3];
                                          fastId=z;
                                  }
                                  kkstr+=childParam[z][0]+"="+childParam[z][3]+"\n";                                 
                          }       
          kkstr+="速度最快的是"+childParam[fastId][0]+"="+childParam[fastId][3];               
          //alert(kkstr);
          document.SpeedTest.elements["show"].value="分站"+childParam[fastId][0]+"网速最快("+childParam[fastId][3]+"秒)";
          document.SpeedTest.elements["gogo"].value="自动转移中请稍后......";
          GoTheFastSite(childParam[fastId][0]);
        }
}
//-------------------------------------------------------------------------------------------------------------------
function GoTheFastSite(url)
{
        REG.action=url+"/index.php?act=register";
        REG.submit();
}
</script>

[/code]

 
【相关文章:】
网址替换自动转向方法

发表评论】【打印此文】【关闭窗口】【点击数:
  • 上一篇文章:
  • 下一篇文章: 没有了
  • 网友评论: