Code for automatically switching CSS skins between ASP, PHP, and JavaScript Based on Time Periods

Source: Internet
Author: User

It is a good idea to automatically adjust the site style based on time. This automatic adjustment of the site style based on time is nothing new. Article Or method, but I didn't pay special attention to it at the time. The following describes their implementation methods. Currently, there are two implementation methods on the Internet:
I. Use server-sideCode
ASP version:
<LINK rel = "stylesheet" type = "text/CSS" href ="
<%
If hour (now) <12 then
Response. Write "morning.css"
Elseif hour (now) <17 then
Response. Write "day.css"
Else
Response. Write "maid"
End if
%>
"/>
PHP version:

<LINK rel = "stylesheet" type = "text/CSS" href ="
<? PHP
$ Hour = Date ("h ");
If ($ hour <12)
Echo 'morning.css ';
Else if ($ hour <17)
Echo 'day.css ';
Else
Echo 'night.css ';
?>
"/>
Ii. use JavaScript code
<SCRIPT type = "text/JavaScript">
<! -
Function getcss (){
Datetoday = new date ();
Timenow = datetoday. gettime ();
Datetoday. settime (timenow );
Thehour = datetoday. gethours ();
If (thehour <12)
Display = "morning.css ";
Else if (thehour <17)
Display = "day.css ";
Else
Display = "maid ";
//(... I want to add more ...)
VaR CSS = '<';
CSS + = 'link rel = "stylesheet" href = '+ display + '\/';
CSS + = '> ';
Document. Write (CSS );
}
->
</SCRIPT>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.