Problem with javascript coding

Programs which generate, solve, and analyze Sudoku puzzles

Problem with javascript coding

Postby pjb » Wed Aug 31, 2016 10:59 pm

Are there any javascript programmers out there?
I've been using code like "document.getElementById(str).style.backgroundColor = "#ccff99";" to dynamically change the color of a cell in my sudoku grid where str will be "a"+x+y. The code used to execute when it was encountered in chrome, firefox and IE. Now it has stopped working in Chrome, but works unchanged in firefox and IE. In chrome, the color change now only appears after the function containing the code finishes. This change seems to have occurred a couple of months ago and I am struggling to find a work-around. This is a pity as I much preferred chrome for its superior performance overall. Am I alone with this problem, and can anyone offer suggestions for a work-around?

Phil
pjb
2014 Supporter
 
Posts: 2552
Joined: 11 September 2011
Location: Sydney, Australia

Re: Problem with javascript coding

Postby JasonLion » Thu Sep 01, 2016 3:45 am

Ideally, you should not assume the screen is going to update until your code has stopped running. This will get to be true more often going into the future, as more browsers optimize more heavily for Javascript speed. Chrome tends to lead the pack in making this kind of optimization.

One workaround is to set a very short timeout to continue your code, and then return. That will result in your code being idle for a moment, and allow the screen to update. Essentially you write your code as a co-rountine instead of a monolithic block. This may or may not be very practical, depending on how your code is currently written.
User avatar
JasonLion
2017 Supporter
 
Posts: 642
Joined: 25 October 2007
Location: Silver Spring, MD, USA


Return to Software