Switch Text Based On Time Of Day


I have a script that I am trying to use to show one text during part of the day and different text during another. I have found a script that would work, but it requires me to use an onload event in the body tag, which it don’t believe I can do in Unbounce. Do anyone know another solution for this?

Here is the code:

var OPENAT = 8;
var CLOSEAT = 18;

function areWeOpen( ) {
var sign = document.getElementById(“openSign”);
var day = new Date().getDay();
var hour = new Date().getHours();
var mins = new Date().getMinutes();
hour = hour + mins/60;
if ( day >=1 && day = OPENAT && hour < CLOSEAT ) {
sign.innerHTML = “555-555-5555”;
sign.className = “OPEN”;
else {
sign.innerHTML = “Sorry, we are now CLOSED”;
sign.className = “CLOSED”;


Hi Dylan,

We included the jQuery Javascript library on all landing pages by default. JQuery has a mechanism for executing Javascript code as soon as the page has loaded. It looks like this:

jQuery(document).ready(function($) {
/* put any code in here that you want to get executed when the document loads */

Hope that helps


That’s great, thanks!


no problem!