Friday, November 27, 2009

Javascript question?

I would like a Javascript that would on holidays redirect the user to a specific (holiday) page but when its not a holiday take them to the normal (home) page.



do you know where i can find one like that?



Javascript question?microsoft word



Sure, just use the Date object.



The entire code would be too lenghty to enumerate in here. Check out http://www.w3schools.com/js/js_obj_date....



This will get you some more information on it.



Javascript question?windows movie maker internet explorer



If you have some experience in JavaScript you can try this ...



1. Store the list of holidays in an array



2. Check if the current date matches with any of the date in the array above.



3. If so redirect to a special page else redirect to your usual page.
Here is the Javascript code that will print if today is holiday.



%26lt;html%26gt;



%26lt;body%26gt;



%26lt;script type="text/javascript"%26gt;



var Datex=new Date();



if ( (Datex.getDay() == 0) || (Datex.getDay() == 6) )



{



document.write("Today it is Holiday");



}



else



{



document.write("Today it Workday");



}



%26lt;/script%26gt;



%26lt;/body%26gt;



%26lt;/html%26gt;



You can try this example online here



http://www.referencedesigner.com/js/try....



You may also like to take a tutorial on the Javascript Date object here



http://www.referencedesigner.com/tutoria...



In actual practice you will one a window based upon not only if today is Sat or Sun but also if it is a national holiday.
We'll use Christmas, New Year's and Halloween as examples. The page for New Year is newyear.htm, the one for Christmas is xmas.htm, Halloween is hw.htm.



%26lt;script type="text/javascript"%26gt;



//Set your site name (be sure to include the slash / after the domain name)



var yourSite = "http://example.com";



//Set the current year



var curYear = "2008";



var now = new Date();



window.onload = function (){



checkDate(new Date("12/25/" + curYear), "xmas.htm");



checkDate(new Date("10/31/" + curYear), "hw.htm")



//Set the next year in order to check for new year



curYear = "2009";



checkDate(new Date("1/1/" + curYear), "newyear.htm");



}



function checkDate(holiday, redirect) {



if (now == holiday) {



location.href += redirect;



}



}



%26lt;/script%26gt;

No comments:

Post a Comment

 
c++