javascriptfitbit

Document.onclick is not firing on fitbit studio



My document.onclick is not firing on fitbit studio. Here is my code:

import document from "document";
var ctally = 0;
const updateTally = () => {
    var fNum;
    if (ctally <= -1) {
        ctally = 0;
        fNum = "000";
    } else if (ctally < 999) {
        fNum = ("00" + ctally).slice(-3).toString();
    } else {
        fNum = ctally.toString();
    }
    document.getElementById("tally").textContent = fNum;
};
// other code... including a document.onkeypress working fine
document.onclick = () => {
    console.log("Hi!");
    ctally++;
    updateTally();
};

I don't know what I did wrong. No errors are produced in either log. Building for Fitbit Versa if it makes a difference. Hi! is not being logged to the console (that is how I knew it was not firing).


Solution

  • document.onclick is not supported on the device.

    Instead, you could create a new element <rect width="100%" height="100%" opacity="0" id="tap-target" pointer-events="all"/> at then end of your GUI file that transparently covers the entire screen, then add the onclick handler to it (document.getElementById('tap-target').onclick = .... This only works in the case where you have no other touch controls on the screen, as this rect will capture all touch events.