Chrome doesn't redraw page when needed
You are using ajax synchronously rather than asynchronously meaning javascript execution halts during the request. To fix make the following change:
XMLHttpRequestObject.open("POST", url, true);
You need to use a callback for the behaviour after the request is complete. Something like this:
function postDataSync(url, params, success)
{
var XMLHttpRequestObject = false;
if (window.XMLHttpRequest)
{
XMLHttpRequestObject = new XMLHttpRequest();
} else
if (window.ActiveXObject)
{
XMLHttpRequestObject = new
ActiveXObject("Microsoft.XMLHttp");
}
if(XMLHttpRequestObject)
{
XMLHttpRequestObject.open("POST", url, true);
XMLHttpRequestObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
XMLHttpRequestObject.send(params);
XMLHttpRequestObject.onreadystatechange = function() {
if (XMLHttpRequestObject.readyState == 4 &&
XMLHttpRequestObject.status == 200)
{
var result = XMLHttpRequestObject.responseText;
delete XMLHttpRequestObject;
XMLHttpRequestObject = null;
if (typeof success === 'function') success(result);
}
}
}
return '';
}
function SaveConfiguration()
{
var errors=checkForm();
if(errors!="")
{
printError("Can't save configuration because there are errors in current tab:<br><br>"+errors);
return;
}
showLoadingScreen(true);
saveTab();
postDataSync('actions/saveconf3.php','', saveComplete);
}
function saveComplete(result) {
showLoadingScreen(false);
alert("Settings saved. The modem is now being reconfigured.");
document.location = "http://" + result;
}
How can I force WebKit to redraw/repaint to propagate style changes?
I found some complicated suggestions and many simple ones that didn’t work, but a comment to one of them by Vasil Dinkov provided a simple solution to force a redraw/repaint that works just fine:
sel.style.display='none';
sel.offsetHeight; // no need to store this anywhere, the reference is enough
sel.style.display='';
I’ll let someone else comment if it works for styles other than “block”.
Thanks, Vasil!
DOM refresh on long running function
SOLVED IT!! No setTimeout()!!!
Tested in Chrome 27.0.1453, Firefox 21.0, Internet 9.0.8112
$("#btn").on("mousedown",function(){
$('#btn').html('working');}).on('mouseup', longFunc);
function longFunc(){
//Do your long running work here...
for (i = 1; i<1003332300; i++) {}
//And on finish....
$('#btn').html('done');
}
DEMO HERE!
Related Topics
JavaScript Get Element by Name
Why Write ≪Script Type="Text/JavaScript"≫ When the Mime Type Is Set by the Server
Can Jquery Get All CSS Styles Associated With an Element
Jqgrid Does Not Render Correctly in Chrome/Chrome Frame
What Do Curly Braces in JavaScript Mean
How to Reload CSS Without Reloading the Page
Loading JavaScript into a Uiwebview from Resources
Why Does Date.Parse Give Incorrect Results
How to Deal With Floating Point Number Precision in JavaScript
Understanding the Difference Between Object.Create() and New Somefunction()
How to Preserve Line Breaks When Getting Text from a Textarea
Forcing Web-Site to Show in Landscape Mode Only
Get Element CSS Property (Width/Height) Value as It Was Set (In Percent/Em/Px/Etc)
Change CSS of Selected Text Using JavaScript