gpt4 book ai didi

javascript - 根据日期重定向到不同的网页

转载 作者:行者123 更新时间:2023-11-30 17:24:54 25 4
gpt4 key购买 nike

我更愿意为此使用 Javascript,但任何语言都可以。

我正在重新设计我的网页。将于7月31日中午12:00发布。我已将站点的两个版本放在不同的目录中。我希望主页上的这段代码能够根据日期将用户重定向到正确的页面。

示例:用户在 6 月 29 日下午 5:00 登录 --> 重定向到/current。用户在 8 月 1 日下午 1:00 登录 --> 重定向到/new。

最佳答案

使用以下 javascript 你可以做到这一点。

// For todays date;
Date.prototype.today = function () {
return ((this.getDate() < 10)?"0":"") + this.getDate() +"/"+(((this.getMonth()+1) < 10)?"0":"") + (this.getMonth()+1) +"/"+ this.getFullYear();
}

if((new Date().today()) >= "01/08/2014")
{
location.href ="new location url";
}
else
{
location.href="current location url";
}

关于javascript - 根据日期重定向到不同的网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24469339/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com