/    Sign up×
Community /Pin to ProfileBookmark

Redirecting a page to another at a given time (not after some seconds)

Hi everyone, I’ve been searching the Internet for days trying to find a javascript that redirects from a page to another at a given time, but the only thing I come across is the typical one which does it after certain seconds.

Does anyone know a way to do the redirect let’s say at 15:32 hours, no matter when the page has been loaded? I’d be really grateful if you could help me!

Regards, Rosana

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@David_HarrisonOct 13.2004 — Put this somewhere in your page:<script type="text/javascript"><!--

var endTime="15:32:00";
var redirPage="http://www.w3.org/";

window.onload=check;

var d, h, m, s;

function check(){

d=new Date();
h=d.getHours().toString();
m=d.getMinutes().toString();
s=d.getSeconds().toString();

if(h.length==1){h="0"+h;}
if(m.length==1){m="0"+m;}
if(s.length==1){s="0"+s;}

if(h+":"+m+":"+s == endTime){
location.href=redirPage;
}else{
setTimeout("check()",1000);
}

}

//--></script>
However, do not rely on the clients computer clock to be correct, many aren't. Also you may have users in different time zones and users with JavaScript disabled (roughly 10% of users do not have JavaScript enabled).

Using JavaScript for this effect will produce vary unreliable results.

The best way to acheive this effect would be to use a server side language and let users view the first page if it is before the cut-off time, but if they arrive after the cut-off time, use a header redirect to take them to a different page.
Copy linkTweet thisAlerts:
@rosanaarbeloauthorOct 13.2004 — Thanks a lot, lavalamp! That script is OK for the purpose I'm looking for.
Copy linkTweet thisAlerts:
@David_HarrisonOct 13.2004 — OK then, happy to help. ?
×

Success!

Help @rosanaarbelo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...