Jump to content

I just redesigned my companies intranet page. It's a small business so the "intranet" really just consists of a HTML page with a bunch of links to queries and network folders. I'm trying to design a script that will change the banner on the website depending on what time of the day it is. For example, if it's 8AM then I want it to have a morning banner and if it's late at night I want it to have a evening banner. I know in jquery you can create a simple time command such as .now() but not sure how I would integrate that to rotate the images. Any help? Thanks.

Link to comment
https://linustechtips.com/topic/330740-javascript-help-needed/
Share on other sites

Link to post
Share on other sites

I'd suggest using something such as getHours(), along with some if then statements.

Specs: CPU - Intel i7 8700K @ 5GHz | GPU - Gigabyte GTX 970 G1 Gaming | Motherboard - ASUS Strix Z370-G WIFI AC | RAM - XPG Gammix DDR4-3000MHz 32GB (2x16GB) | Main Drive - Samsung 850 Evo 500GB M.2 | Other Drives - 7TB/3 Drives | CPU Cooler - Corsair H100i Pro | Case - Fractal Design Define C Mini TG | Power Supply - EVGA G3 850W

Link to comment
https://linustechtips.com/topic/330740-javascript-help-needed/#findComment-4490371
Share on other sites

Link to post
Share on other sites

time = Date.getHours()if (time > 6 && time < 12){   document.getElementById('bannerWrapper').innerHTML = '<img src="morningBanner.jpg">'}else if (time >= 12 && time < 18){   document.getElementById('bannerWrapper').innerHTML = '<img src="eveningBanner.jpg">}

Pure Javascript. Basically, get the hour(24 hour format) and change what gets displayed inside bannerWrapper to the image you want to display. Of course, if you didn't want a wrapper you can change the image source with javascript too. But it's probably easier to just create a wrapper if that's the case

 

EDIT: Well, I was too slow :(

I am good at computer

Spoiler

Motherboard: Gigabyte G1 sniper 3 | CPU: Intel 3770k @5.1Ghz | RAM: 32Gb G.Skill Ripjaws X @1600Mhz | Graphics card: EVGA 980 Ti SC | HDD: Seagate barracuda 3298534883327.74B + Samsung OEM 5400rpm drive + Seatgate barracude 2TB | PSU: Cougar CMX 1200w | CPU cooler: Custom loop

Link to comment
https://linustechtips.com/topic/330740-javascript-help-needed/#findComment-4490397
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×