0

I am trying to make an hta with a countdown timer. I have a timer that works fine in html but when i put the code in to an hta it gives an error. I have also tried running the html version inside of an iframe n an hta. Any help is appreciated.

function startTimer(duration, display) {
    var timer = duration, minutes, seconds;
    setInterval(function () {
        minutes = parseInt(timer / 60, 10)
        seconds = parseInt(timer % 60, 10);

        minutes = minutes < 10 ? "0" + minutes : minutes;
        seconds = seconds < 10 ? "0" + seconds : seconds;

        display.textContent = minutes + ":" + seconds;

        if (--timer < 0) {
            timer = duration;
        }
    }, 1000);
}

window.onload = function () {
    var fiveMinutes = 60 * 60,
        display = document.querySelector('#time');
    startTimer(fiveMinutes, display);
};
</script>
<body>
<font color="red" size="7">
<big>
    <div> <span id="time">60:00</span></div>
</big>
</font>
</body>


 <body background="image1.jpg">
  • To use `querySelector` you have to run the HTA in IE8 mode at minimum. Also `textContent` wasn't available before IE9. See https://stackoverflow.com/questions/19567887/javascript-version-in-hta/19570684#19570684 . – Teemu Aug 25 '17 at 19:19

2 Answers2

0

You need to add your scripts after your body, not before it. I can't really tell based on the code you have posted, but with the closing </script> tag it seems as though this is what you have done.

Francisco Flores
  • 290
  • 2
  • 16
0

You can try changing:

display = document.querySelector('#time');

to

document.getElementById('time');

It would be more vanilla JavaScript... Also change the span to a div with inline-block.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Carlos Alves Jorge
  • 1,919
  • 1
  • 13
  • 29
  • i changed the js to this, with no results. still works in html, not in hta. also inline block is unnecessary for this project. it fits right where it is supposed to. – Rick Sanchez Aug 26 '17 at 22:46
  • Do you get any error? Can you try to make all your variables local to make sure there are no interferences with same name variables somewhere? var display, var minutes so on? Shouldn't the that though really... – Carlos Alves Jorge Aug 27 '17 at 15:58
  • no errors. the hta opens and displays 60:00 fine, but it never changes after that. – Rick Sanchez Sep 02 '17 at 20:38