File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes How to force a browser to redraw ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to force a browser to redraw ?" Watch "How to force a browser to redraw ?" New topic
Author

How to force a browser to redraw ?

Jay Damon
Ranch Hand

Joined: Jul 31, 2001
Posts: 282
Is there any way to force a browser to redraw the page or perhaps even a specific element? I have page which contains a table which contain a cell that may overflow. I embedded a DIV in the table cell to allow for the overflow. It works great in IE and Safari (Windows).

However, in Firefox and Opera, it does not. Using info from a previous post in this forum, I attempt to dynamically set the DIV height in Firefox/Opera. This works in both Firefox and Opera but, after the page has been loaded in Firefox, The cell retains it original height (as laid out originally by Firefox) AFTER the DIV height has been set. If I resize the page, Firefox will correctly resize the table cell/div but it will not do so on a page load. How do I force Firefox to redraw in the onload event?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Well you should watch with onresize and call the code that sets the height of the div again like you do for onload.

Eric
Jay Damon
Ranch Hand

Joined: Jul 31, 2001
Posts: 282
Actually I am calling the same function in my onload script as is attached to window.onresize. My point is that Firefox does not resize when executed during page load. It sets the DIV height correctly (confirmed) but does not redraw the element until an onresize event is fired. I might add that I have tried setting the TD height as well to no avail. Once a resize occurs, the page elements are redrawn and appear as they should. I have to set the DIV height for Opera as well and, once the DIV height is set, the affected elements are redrawn and the page appears as it should.

This is only a problem in Firefox (2.0.0.11) and only on page load. Curiously, if I use the Web Developer tools to attempt to outline the TD/DIV elements in the page, an onresize event is apparently triggered and again Firefox renders the page as it should.

So my question is again is how to force a redraw? Right now, I'm thinking that I should just change some other arbitrary element in an attempt to trigger a redraw.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Sounds like a timing issue. What is the line you are using to change the div?

Eric
Jay Damon
Ranch Hand

Joined: Jul 31, 2001
Posts: 282
Well, it just starting working. The only thing I did was close Firefox and restart it. Issue resolved I guess. Thanks for your help Eric!
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Wondering if there was a caching issue or something like that...You never know with JavaScript. LOL...

If it acts up again, you might want to look at adding a few millisecond delay after onload. Seems like that helps someties with things that do not get built right. I have had to use that little hack myself a few times.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to force a browser to redraw ?