我做了一些研究,但找不到我要找的东西。
基本上,我只想根据特定日期更改重定向。它用于降临节日历,因此用户将单击“查看我们的降临节日历”链接,根据日期(12 月 1 日、2 日、3 日……),他们将看到 12 月每一天的不同网页。
我认为这可能是简单的事情,例如:
<script language="JavaScript">
var currentDate = new Date().getDate();
if (currentDate = 2014,11,26)
window.location = "http://www.yahoo.com";
else if (currentDate = 2014,11,27)
window.location = "http://www.youtube.com";
else if (currentDate = 2014,10,28)
window.location = "http://www.google.com";
</script>
(我会用我的实际链接替换 Google/youtube/etc,但无论日期是什么,它只会转到第一个链接)
我尝试过不同的日期格式,包括 YYYY/MM/DD 和年/月/日/小时/秒/毫秒。
如果这很容易做到,而且我错过了一些明显的东西,我深表歉意。但你可以通过提问来学习...
最佳答案
您的位置部分很好。这是您的代码缺少的比较部分..您可以这样做
var date = new Date() // construct a Date instance
.toISOString() // convert into ISO time
.split('T')[0]; // this will result in "2013-11-26"
if(date == "your date in the format year-month-day here"){
window.location.href = "your url here";
}
关于javascript - 根据日期重定向到不同的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27151008/