setTimeout() and setInterval() behave oddly in GeogebraBooks

Anh Huy Truong shared this problem 3 years ago
New

I have created a number of apps using setInterval() and/or setTimeout() functions. They work as they should when I open the apps directly in web (e.g. https://ggbm.at/Fgcr47Df). However, when I use them in a GeogebraBook (e.g. https://www.geogebra.org/m/...), the timers seem to be vastly incorrect. More precisely, the pseudo-tooltip I've created disappears much faster than intended (3 seconds). Sometimes, the bug doesn't immediatly occur but I can always reproduce it by switching apps using the navigation on the LHS. Is this a known bug? Is there a workaround I could use in the meantime?

Comments (2)

photo
1

I think the problem is that the interval keeps running after you switch between pages of the book. Please consider something like

clearInterval(window.tooltipBijeciveTimer);

tooltipBijeciveTimer=setInterval(function(){ ...}, 1000);


Even better is to get rid of JS completely; create a hidden animated slider and append a GeoGebra script to update event of that slider.

photo
1

Thank you for suggestion. Unfortunately, the clearInterval() command doesn't work for me. I suspect this is due to the fact, that Geogebra doesn't support global JS-variables to begin with. I've been googling and troubleshooting for the past hour, mostly looking for ways to clear all intervals, but none of the methods found on stackexchange etc. worked properly (expect for the loop through all IDs from 0 to 99999, but that slows down the applet significantly, making it unusable). Do you have any suggestion how I could access the setInterval ID?


I already tried using a hidden animated slider some time ago but in some applets, I need multiple different times which makes it difficult or even impossible to get the timings right, since I rely on the JS-OnClickListener and in JS, there is only a startAnimation() command which starts all timers at once.

photo
© 2020 International GeoGebra Institute