Time Of Day Based Dynamic Changes Via With Code?

Hi,

I want to use code that will allow me to change a background of a strip or a page or other content on the page based on different time of days as READ FROM visitsor computer/device settings. I previoiusly employed redirects to get this done when I needed such things, with multiple versions of the same page for different times of day.

Is this going to be possible directly using Wix Code any time soon? If so, a little guidance on how it might be done would be appreciated.

Basically, I want my page to be able to show GOOD MORNING message via a dynamicly/code depenedent text element if you will and a background picture that goes well with morning time… and say good afternoon and show an afternoon related image on page backgroujnd for afternoon, and so on for evening. I know my time brackets and just need to know if I can accomplish this via a single dynamic page / url AS opposed to having to workaround and do those kinds of things.

Thanks!
Omid

Can you change the image through code?

Hello Omid,

Yes this is possible using Wix code, below I have created a boilerplate for you to use.
You can find more information on date.getHours() - here , and background.src - here .

const date = new Date();       //Get the current Date
const hour = date.getHours();  //We get the hour here (0-23)

if(hour <= 12){                //Customize the hours according to your preference 
  $w('#greetingText').text = 'Good Morning';
  $w("#greetingImage").background.src = "http://placehold.it/250x250";  //Your good-morning Image
}else {
  $w('#greetingText').text = 'Good Afternoon';
  $w("#greetingImage").background.src = "http://placehold.it/250x250";  //Your good-afternoon Image
}                          

Hope this helps,
Majd

1 Like

Majd, Vielen Dank mein Freund!