Jun 20, 2006

Safari JavaScript problems

Today I spent several hours fixing various bugs in Team Server for another EAP release, and two of them concerned Javascript issues in the Safari browser.

The first issue:
In Safari you cannot specify the location of an absolutely positioned element if this element has display:none. I had a code which set style.left and style.top of a hidden div and then showed it on the screen. It worked fine in every browser except Safari. To make it work, I had to assign display:block to the div first, and then assign coordinates.

The second issue - how to add a mouse document listener.
Again, code like Event.observe(document.body, "mousedown", handler) worked out in every browser. Except Safari. In Safari one has to use 'useCapture' option when adding the event handler, i.e. use Event.observe(document.body, "mousedown", handler, true).

I tried to google for the solution of my problems with Safari, but failed. Hence this post. Hope this saves someone's time and headache :)


Technorati: