XF 1.5 Make javascript only work on specific dates possible?

borgqueenx

Active member
Im having some javascripts on my site (snow effect) and it works/gets called by an edit in a template file.
I want it to work on between 20 december and 20 january. is there a way to do this?
 
Why use a conditional inside the JS file to enable or disable it whereas you can simply use XenForo Templates Conditionals to load or not your JS on your page? Just wrap the require:js line between a conditional. It will prevent to load unnecessary code for the other 11 months of the year.
 
i tried this but just get a large piece of code on my main site, instead of the actual effect working.
var now = new Date();
if (now >= new Date(now.getFullYear(), 11, 7) && now <= new Date(now.getFullYear() + 1, 0, 20)) {
<xen:require js="js/xenforo/snowfall.jquery.min.js"/>
<script>
$(document).snowfall({flakeCount : 95, maxSpeed : 10, maxSize : 5,round : true});
</script>
}
 
You're putting script tags in the JS - the script tags should be between your JS (i.e. before the first var and after the last parenthesis)
understanding the years etc. since january is 0, is the first of the month also the 0's in script? So if i want to activate it the 20th do i put 19?
 
Top Bottom