How to dynamically load different css files based on time? _html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:24:18
Original
1197 people have browsed it

According to the time, the CSS files used during the day are loaded during the day, and the CSS files used at night are loaded at night.

How to achieve it?


Reply to discussion (solution)

If it is the server side
judge the time, then
" rel="stylesheet" type="text/css" />
That’s it

If you use js
you can


window.onload=function(){
var d = new Date().getHours();
if(d>8 && d < 18){
document.getElementById("css").setAttribute("href","day.css")
}else{
document. getElementById("css").setAttribute("href","night.css")
}
}

or
var c = "night.css"
if( d>8 && d < 18){
c="day.css"
}
document.write('')

It is best to judge on the server side.
If it is PHP, you can use apache rewrite url to rewrite a style.php file into style.css
and then the output format can be like this style.css?date=1380644282

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template