?
Solved

Day of Week Redirect

Posted on 2003-10-30
19
Medium Priority
?
317 Views
Last Modified: 2010-04-06
Ok, heres my problem.  I need some type of script, be it javascript or vbscript or something that will let me load a different web page depending on the day of the week.  For example, i need to load index.htm on every day of the week except sundays.  on sundays, i want to load sunspecial.htm. Is there any way I can do this? I've been searching the web like a maniac trying to find answers but couldn't find anything that worked properly.  It's not a real complicated web site, just a few htm pages.
0
Comment
Question by:ddh86
  • 6
  • 6
  • 5
  • +1
19 Comments
 
LVL 13

Expert Comment

by:lozloz
ID: 9654997
if you have php installed..

change index.htm to index.php and add this code at the very top of the page:

<?
$date = date("w");
if($date == 0) {
  header("Location: sunspecial.htm");
  exit;
}
?>
0
 
LVL 12

Expert Comment

by:kingsfan76
ID: 9654998
should be able to accomplish this with VBscript

<%
if WeekDay(Date) = 1    'today is Sunday
   response.redirect("sunspecial.htm")
else   'today is not sunday
   response.redirect("index.htm")
end if
%>

Weekday() function return the day of the week (1=sunday, 2=monday, etc.)

hope this helps   :-)
0
 

Author Comment

by:ddh86
ID: 9655201
Ok here's the status: neither of your solutions worked. I tried each one separately, and neither seem to react when i change my system clock to sunday. both give the same response on any day of the week.

one more question, kingsfan76: is sunday = 1 or 0? I tried it both ways.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:lozloz
ID: 9655242
changing your system clock won't work, they both use the server's clock. are you sure you have asp or php available on your sever? and sunday is 1 in asp and 0 in php afaik

loz
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9655453
Javascript Solution

Sunday = 0

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--Begin
function redirect(){
      var d = new Date();
      var today = d.getDay();
      if(today == 0){      location.href = "http://yahoo.com"; }
      else if(today == 1){ location.href = "http://microsoft.com"; }
      else if(today == 2){ location.href = "http://netscape.com"; }
      else if(today == 3){ location.href = "http://w3schools.com"; }
      else if(today == 4){ location.href = "http://oldlook.experts-exchange.com"; }
      else if(today == 5){ location.href = "http://experts-exchange.com"; }
      else if(today == 6){ location.href = "http://google.com"; }      
}
//End-->
</script>
</head>
<body onload="redirect();">

</body>
</html>
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9655462
or this

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--Begin
var weekdays = new Array(7);
      weekdays[0] = "sunday";
      weekdays[1] = "monday";
      weekdays[2] = "tuesday";
      weekdays[3] = "wednesday";
      weekdays[4] = "thursday";
      weekdays[5] = "friday";
      weekdays[6] = "saturday";
function redirect(){
      var d = new Date();
      var today = d.getDay();
      if(today == 0){      location.href = "http://yoursite.com/"+ weekdays[0]; }
      else if(today == 1){ location.href = "http://yoursite.com/"+ weekdays[1]; }
      else if(today == 2){ location.href = "http://yoursite.com/"+ weekdays[2]; }
      else if(today == 3){ location.href = "http://yoursite.com/"+ weekdays[3]; }
      else if(today == 4){ location.href = "http://yoursite.com/"+ weekdays[4]; }
      else if(today == 5){ location.href = "http://yoursite.com/"+ weekdays[5]"; }
      else if(today == 6){ location.href = "http://yoursite.com/"+ weekdays[6]; }      
}
//End-->
</script>
</head>
<body onload="redirect();">

</body>
</html>
0
 

Author Comment

by:ddh86
ID: 9657223
ok thanks guys, ya gotta give me a chance to try them now.

javascript is client-side, right?
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9657587
Yes JS is Clientside
0
 

Author Comment

by:ddh86
ID: 9659534
hi jaysolomon: I used your first solution, and it works, the only problem is this: it first loads the entire index.htm page, and afterward redirects to sun.htm.  This works for me because i have DSL, but on dialup it'd be torture.  Can we fix that?

Thanx
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9659626
rename index.htm to something else and have that code in your new index.htm?
0
 

Author Comment

by:ddh86
ID: 9659882
Actually I'd prefer not to do that, I really want to keep the number of pages at a minimum.

Is there a way to execute that javascript before the entire page loads?
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9659933
not that i know of, im not the best at javascript though. both the asp and php scripts will process before the page loads though
0
 

Author Comment

by:ddh86
ID: 9660002
The problem with the asp and php is that i don't know how to test it to see if it works. . .

wait a minute. if i ran the html off my desktop, would it treat my computer as the server and run the script? that way i can set my clock to sunday and test it.
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9660090
no, you need php installed on a web server such as IIS or apache

but it will definitely work if you tell me the result of doing this:

<?
$date = mktime(0,0,0,11,2,2003);
$thedate = date("l - w", $date);
print $thedate;
?>

that simulates the day as 2nd of november and will return the day and index, so you'll know it works
0
 
LVL 12

Expert Comment

by:kingsfan76
ID: 9660169
to test if it works, jsut do this:

<%
testDate = CDate("10/26/2003")     'i believe that was a Sunday
if WeekDay(testDate) = 1  then   'today is Sunday
  response.redirect("sunspecial.htm")
else   'today is not sunday
  response.redirect("index.htm")
end if
%>
0
 
LVL 16

Accepted Solution

by:
jaysolomon earned 1000 total points
ID: 9660211
You can try to take the onload out of the body and take the function name out

<script type="text/javascript">
<!--Begin
     var d = new Date();
     var today = d.getDay();
     if(today == 0){     location.href = "http://yahoo.com"; }
     else if(today == 1){ location.href = "http://microsoft.com"; }
     else if(today == 2){ location.href = "http://netscape.com"; }
     else if(today == 3){ location.href = "http://w3schools.com"; }
     else if(today == 4){ location.href = "http://oldlook.experts-exchange.com"; }
     else if(today == 5){ location.href = "http://experts-exchange.com"; }
     else if(today == 6){ location.href = "http://google.com"; }    
//End-->
</script>
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9660216
If you have asp it would be better
0
 

Author Comment

by:ddh86
ID: 9660352
jaysolomon - it looks like you're gettin the points! it works like a charm now.  Thanks a ton, all of you!
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9660395
Glad we could help and thanks for the A

BTW
Here is you an asp solution
<%
      If weekday(date) = 1 Then      'Sunday
      response.redirect("http://yoursite.com/sunday.asp")
End If
%>
<%
If weekday(date) = 2 Then      'Monday
response.redirect("http://yoursite.com/monday.asp")
End If
%>
<%
      If weekday(date) = 3 Then      'Tuesday
      response.redirect("http://yoursite.com/tuesday.asp")
End If
%>
<%
      If weekday(date) = 4 Then      'Wednesday
      response.redirect("http://yoursite.com/wednesday.asp")
End If
%>
<%
      If weekday(date) = 5 Then      'Thursday
      response.redirect("http://yoursite.com/thursday.asp")
End If
%>
<%
      If weekday(date) = 6 Then      'Friday
      response.redirect("http://yoursite.com/friday.asp")
End If
%>
<%
      If weekday(date) = 7 Then      'Saturday
      response.redirect("http://yoursite.com/saturday.asp")
End If
%>
 

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

</body>
</html>
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question