I am struggling to get custom JS to work in Unbounce. If anyone has a moment, I’d love some help.
Thank you!!!
I’ve spent the last week attempting to learn JS to build this feature without success. My current JS code has the chat availability hours in UTC Hours as Unbounce help confirmed rather than user’s time.
We would like the Chat button (placeholder for now) to show when Chat is online (specific hours: M-F 730a-530p MST, Sat 9a-1p, Sun closed) and hide when Chat is offline and show the headline+form during Chat offline hours.
THIS IS A LIVE PAGE FOR TESTING ONLY - PLEASE DO NOT FILL OUT AND SUBMIT FORM
PROBLEM:
It appears the Click to Chat button shows at all times and the form shows during off hours but the hours don’t always seem to be correct either.
Code below references:
Click-to-Chat - #lp-code-285
Form Headline - #lp-pom-text-187
Form - #lp-pom-form-127
JS Code (remember I am new to Javascript):
<script type="text/javascript">
//gets the current time.
var d = new Date();
var CurrentDay = d.getUTCDay();
if(CurrentDay == 1 && d.getUTCHours() >= 1330 && d.getUTCHours() <= 2330 ){
$("#lp-code-285").hide();
$("#lp-pom-text-187").show();
$("#lp-pom-form-127").show();
}
else if(CurrentDay == 2 && d.getUTCHours() >= 1330 && d.getUTCHours() <= 2330 ){
$("#lp-code-285").hide();
$("#lp-pom-text-187").show();
$("#lp-pom-form-127").show();
}
else if(CurrentDay == 3 && d.getUTCHours() >= 1330 && d.getUTCHours() <= 2330 ){
$("#lp-code-285").hide();
$("#lp-pom-text-187").show();
$("#lp-pom-form-127").show();
}
else if(CurrentDay == 4 && d.getUTCHours() >= 1330 && d.getUTCHours() <= 2330 ){
$("#lp-code-285").hide();
$("#lp-pom-text-187").show();
$("#lp-pom-form-127").show();
}
else if(CurrentDay == 5 && d.getUTCHours() >= 1330 && d.getUTCHours() <= 2330 ){
$("#lp-code-285").hide();
$("#lp-pom-text-187").show();
$("#lp-pom-form-127").show();
}
else if(CurrentDay == 6 && d.getUTCHours() >= 15 && d.getUTCHours() <= 17 ){
$("#lp-code-285").show();
$("#lp-pom-text-187").hide();
$("#lp-pom-form-127").hide();
}
else {
$("#lp-code-285").hide();
$("#lp-pom-text-187").show();
$("#lp-pom-form-127").show();
}
</script>