• I’m using Woocommerce and Storefront theme. I’ve added a simple java countdown timer to a single page direct in the (text) editor. It works but was wondering:

    1. Should it work? I assumed WordPress would delete it upon saving.
    2. Can it cause any security issues?

    <script>
    function makeMeTwoDigits(n){
        return (n < 10 ? "0" : "") + n;
    }
    // Set the date we're counting down to
    var countDownDate = new Date("oct 20, 2019 15:37:25").getTime();
    
    // Update the count down every 1 second
    var x = setInterval(function() {
    
      // Get today's date and time
      var now = new Date().getTime();
        
      // Find the distance between now and the count down date
      var distance = countDownDate - now;
        
      // Time calculations for days, hours, minutes and seconds
      var days = Math.floor(distance / (1000 * 60 * 60 * 24));
      var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
      var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
      var seconds = Math.floor((distance % (1000 * 60)) / 1000);
        
      // Output the result in an element with id="dhms"
      document.getElementById("dhms").innerHTML = 
      
      "<div class='dhmsnums'>" + makeMeTwoDigits(days) + "<span class='dhmstext'>d</span></div>" + 
      "<div class='dhmsnums'>" + makeMeTwoDigits(hours) + "<span class='dhmstext'>h</span></div>" 
      +   "<div class='dhmsnums'>" + makeMeTwoDigits(minutes) + "<span class='dhmstext'>m</span></div>" 
      +   "<div class='dhmsnums'>" + makeMeTwoDigits(seconds) + "<span class='dhmstext'>s</span></div>";
        
      // If the count down is over, write some text 
      if (distance < 0) {
        clearInterval(x);
        document.getElementById("dhms").innerHTML = "EXPIRED";
      }
    }, 1000);
    </script>
    • This topic was modified 6 years, 5 months ago by Jan Dembowski.
Viewing 1 replies (of 1 total)
  • Tyler

    (@tylerthedude)

    Hi there,

    I’m not entirely sure that WordPress will delete the page upon the expiration set in the script since it’s embedded directly in the page, but it might. If it doesn’t, then you can always manually delete the page in question.

    As for the potential security vulnerability – From looking over the script, no functions appear to be called incorrectly and the script seems to be well-defined. You can always check your console on this page and see if it returns with any type of false/positives.

    Thanks!
    Tyler

Viewing 1 replies (of 1 total)

The topic ‘Adding Java direct to page (editor)’ is closed to new replies.