我想通过使用javascript实现url点击链接随机方法。javascript循环链接点击
例如,如果访客A,B,C,d访问我的网站
,如果点击URL链接,我想游客参观我的两个网站example1.com和example2.com随机。
<area shape="rect" coords="140,350,890,440" href="http://somesite.com" target="_blank">
我发现了一些JavaScript的数组方法,但我怎么能修改它,可以采用我的情况?
<SCRIPT Language="Javascript">
<!--
function Randomlink()
{
Url = new Array;
Url[0] = "http://www.ccm.net/index.php3";
Url[1] = "http://www. ccm.net/wifi";
Url[2] = "http://www. ccm.net/php";
Url[3] = "http://www. ccm.net/forum/";
Chooselink = Math.round(Math.random() * (Url.length+1));
window.open(Url[Chooselink],'_blank');
}
//-->
</SCRIPT>
在这个算法中使用Math.round()并不能给你均匀的分布。看例子:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random – cgatian