基于本地时间的月份重定向Javascript
我正在开发一个网站,有人告诉我,基于特定的月份,我们希望用户直接访问特定月份的页面。一月将转到一月.html,例如,二月到二月.html。我创建了以下脚本,由于某些原因无法重定向页面 任何帮助都将不胜感激! 谢谢 尼克基于本地时间的月份重定向Javascript,javascript,php,Javascript,Php,我正在开发一个网站,有人告诉我,基于特定的月份,我们希望用户直接访问特定月份的页面。一月将转到一月.html,例如,二月到二月.html。我创建了以下脚本,由于某些原因无法重定向页面 任何帮助都将不胜感激! 谢谢 尼克 函数initArray(){ this.length=initArray.arguments.length; for(var i=0;i
函数initArray(){
this.length=initArray.arguments.length;
for(var i=0;i
我认为您可能有比实际需要更多的代码
要以数字形式获取当前月份,您可以使用:
var dt = new Date();
var currentDate = currentDate.getMonth() + 1;
然后您可以使用
if (currentDate == 1) [...]
你想要的方式
作为旁注,使用switch而不是无数的if()语句会更清楚(也更合适):
switch(currentDate){
case 1: window.location.href='/somesite/january.html';
case 2: window.location.href='/somesite/february.html';
case 3: window.location.href='/somesite/march.html';
case 4: window.location.href='/somesite/april.html';
/* and so on */
}
也许你想把一切都复杂化。 您可以通过一行PHP实现这一点。 这里有一行代码可以工作
<?php header('Location:'."http://www.example.com/".date(F).".html");?>
请发布您的脚本。欢迎来到这里。感谢GG和qwenrtynl!上面发布的脚本点击提交太快。
<?php header('Location:'."http://www.example.com/".date(F).".html");?>