tailieunhanh - CSS Cookbook- P14

Tham khảo tài liệu 'css cookbook- p14', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Applying a Different Stylesheet Based on the Time of Day Problem You want to apply a different stylesheet as the day progresses. Solution Pull in the time on the user s clock and deliver the appropriate stylesheet script type text javascript function setTimedStylesheet var theTime new Date .getHours if 8 theTime theTime 20 link rel stylesheet href type text css if 20 theTime theTime 8 link rel stylesheet href type text css setTimedStylesheet script Make sure you include the noscript element that includes a link to the default stylesheet in case the browser does not have JavaScript script type text javascript function setTimedStylesheet var theTime new Date .getHours if 8 theTime theTime 20 link rel stylesheet href type text css if 20 theTime theTime 8 link rel stylesheet href type text css setTimedStylesheet script noscript link href rel stylesheet type text css noscript Discussion Creating a customized look and feel based on the time of day isn t a far-fetched notion. Radio and television stations in the United States divide their broadcasts based on the time of day for example Daytime Emmy Awards drive-time radio shows prime time television shows and so on. Applying a Different Stylesheet Based on the Time of Day 625 Please purchase PDF Split-Merge on to remove this watermark. The main problem with using this method is that you are assuming the clocks on people s computers are actually accurate. Another solution is to get the time of day from your server through a middleware programming language such as PHP and pass it on as a variable to the JavaScript. See Also The Date object reference at http jsref Redirecting to a Mobile Site Based on the Browser s Screen Width Problem You want to apply a change to the stylesheet based on the browser s screen width. Solution Detect the

TỪ KHÓA LIÊN QUAN