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 :)



antonio said...

Hi there Kir,

I have same problem but for different reasons, my code works in every browser except, guess what, Safari...

What I am trying to do is to render dynamically a movie within a layer, then display the layer... Once I inserted the code, I put the following function:

Event.observe('flashmovie','focus',function () {
$('flashmovie').blur(); // return focus to our self window

But, unfortunately it doesnt work... I just want to get trap the focus event and return focus to main window, in order to keep track on keyboard events...

Any ideas?

Being for hours on Google no solution has been found...


Kir Maximov said...

Hi Toni,

Are you sure that your code isn't called? Did you try to insert alert() to your handler? Possibly, you have to call something like window.focus() instead of $('flashmovie').blur();


ashis lun said...

Hi Kir,

I tried observing the elements which is inside Redbox with Event.observe(element, event, handler, true) but its' not working for me in safari.

Any idea?


Kir Maximov said...


The matter is, in the latest versions of Prototype 'useCapture' parameter has been removed. I've created an issue in the tracker for this problem (and there is a patch): http://dev.rubyonrails.org/ticket/10654


Anonymous said...

You the man. Thanks for posting this. I still have hair thanks to you.