Pbeyrouty Posted June 21, 2013 Posted June 21, 2013 I have a small bug I was hoping someone might be able to help me with. I made a very simple JavaScript timer to display the amount of time spent on a task. Obviously it needs to display through the web viewer. It works well enough, however it sometimes causes Filemaker to get stuck when I attempt to leave the layout. This happens in FileMaker Pro and Go. Has anyone ever encountered a similar problem. I've added the code. It currently had a button to activate it for while I'm testing but I'm planning on having it load automatically. "data:text/html," &" <html> <head> <script type="text/javascript"> function setCount() { var start = " & GetAsNumber(TimePoints|Today_Workers::Time.Start) & "; var d = new Date(); var t = d.getHours()*3600 + d.getMinutes()*60 + d.getSeconds(); var diff = t - start; var h = Math.floor(diff/3600); var m = Math.floor( (diff - h*3600)/60); var s = diff - h*3600 - m*60; if(h<10) {h='0'+h;} if(m<10) {m='0'+m;} if(s<10) {s='0'+s;} var soFar = h + ':' + m + ':' + s; document.getElementById('timer').innerHTML = soFar; var run = setInterval( function(){setCount()},1000); } </script> </head> <body> <p align="center">Time so far is: <b id='timer'>??</b> <input type='button' onclick='setCount()' value='Show the Time'/> </p> </body></html>"
Pbeyrouty Posted July 1, 2013 Author Posted July 1, 2013 Ok, it turns out that I made a stupid mistake. Since I'm not too familiar with JavaScript I wasn't considering how the interval function worked. I just realized that by putting setInterval in the function, it was starting a new cycle of timer updates everytime it ran. In other words, every time it ran it created a duplicate timer. This would increase exponentially every second. This inevitably took up all of the resources allocated to FileMaker. By putting setInterval into a separate function it will run the original function every second without a problem.
Recommended Posts
This topic is 4430 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now