Archive
Forcing Safari to Repaint
Yesterday I had to debug a script in Safari. The debugging process included a dude's PowerBook and a lot of effort. Problem in case: appending an embed element does not seem to work: Safari doesn't repaint to show the element. Surprisingly Safari did show it when I used innerHTML.
In my quest to solve the problem I found a site which stated that Safari wouldn't repaint if you changed a text node. My subconsciousness combined this with the fact that innerHTML did work, and shot it's conclusion back into my mind when I tried to get some sleep (of course this kept me from sleeping, sigh).
So, to get to the gist of this post: if you append an element using a DOM method and Safari won't repaint, add something using innerHTML afterwards:
element.innerHTML += "";
Appearantly changing the innerHTML property forces Safari to repaint. Odd, but it works.
Small update: it works with an empty string as well.
Comments
Leave a Comment
Due to some recent spam, and because this site is no longer active I've decided to disable comments side-wide. You can always mail me if you have questions. Thanks!
Joe wrote:
Interesting…. the other day I created a bookmarklet called “Annotate Links” (see URI). This appends a reference number after all external links on a page and appends a list of referenced URLs at the bottom of the page.
Works nicely in Mozilla and MSIE but Safari refuses to allocate extra space for the reference numbers in the link elements.
Gotta give this hint a try!
September 10, 2004 @ 1:49 pm. Type: Comment. Permalink.