Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
希望按月进行Javascript重定向吗_Javascript_Arrays_Redirect - Fatal编程技术网

希望按月进行Javascript重定向吗

希望按月进行Javascript重定向吗,javascript,arrays,redirect,Javascript,Arrays,Redirect,我正在制作一个index.html页面,每个月重定向到不同的页面。这是我的投资组合。其思想是,每次访问index.html页面时,它都会自动重定向到设置为特定月份的页面。假设我想看看我投资的哪些公司将在本月(4月)宣布除息日期,我转到index.html,它将转到4月的特定页面 我去这个网站获取随机重定向代码:() 以下是他们的代码: <script type="text/javascript"> var urls = new Array(); urls[0]

我正在制作一个index.html页面,每个月重定向到不同的页面。这是我的投资组合。其思想是,每次访问index.html页面时,它都会自动重定向到设置为特定月份的页面。假设我想看看我投资的哪些公司将在本月(4月)宣布除息日期,我转到index.html,它将转到4月的特定页面

我去这个网站获取随机重定向代码:()

以下是他们的代码:

<script type="text/javascript">

var urls = new Array();
urls[0] = "http://learninginhand.com";
urls[1] = "http://learninginhand.com/about";
urls[2] = "http://learninginhand.com/contact";
urls[4] = "http://learninginhand.com/services";
urls[5] = "http://learninginhand.com/videos";
urls[6] = "http://learninginhand.com/infographics";
urls[7] = "http://learninginhand.com/resources";
urls[8] = "http://learninginhand.com/stickaround";
urls[9] = "http://learninginhand.com/posts";
urls[10] = "http://learninginhand.com/pet";

var random = Math.floor(Math.random()*urls.length);

window.location = urls[random];

</script>

var url=新数组();
URL[0]=”http://learninginhand.com";
URL[1]=”http://learninginhand.com/about";
URL[2]=”http://learninginhand.com/contact";
URL[4]=”http://learninginhand.com/services";
URL[5]=”http://learninginhand.com/videos";
URL[6]=”http://learninginhand.com/infographics";
URL[7]=”http://learninginhand.com/resources";
URL[8]=”http://learninginhand.com/stickaround";
URL[9]=”http://learninginhand.com/posts";
URL[10]=”http://learninginhand.com/pet";
var random=Math.floor(Math.random()*url.length);
window.location=URL[随机];

我需要使用JavaScript来获取月份。这一页有帮助:()

这是他们在上述网站上的代码:

var d = new Date();
var n = d.getMonth();
由于JavaScript在随机数代码中包含0,因此我必须添加一些代码使其加上1

然后我更改了数组代码:

var urls = new Array();
urls[1] = "01.html";
urls[2] = "02.html";
urls[3] = "03.html";
urls[4] = "04.html";
urls[5] = "05.html";
urls[6] = "06.html";
urls[7] = "07.html";
urls[8] = "08.html";
urls[9] = "09.html";
urls[10] = "10.html";
urls[11] = "11.html";
urls[12] = "12.html";
在()页中显示的代码中,这是重定向发生的地方:

var random = Math.floor(Math.random()*urls.length);

window.location = urls[random];

</script>
var random=Math.floor(Math.random()*url.length);
window.location=URL[随机];
我把它改成这样:

var random = n

window.location = urls[random];

</script>
var random=n
window.location=URL[随机];
我拿走了Math.floor(Math.random()*url.length);var random去的地方,用n代替它

var random = n

window.location = urls[random];

</script>