The Occasional Occurence

Safari Gotchas

August 16, 2007 at 09:56 PM | categories: work, Software, computing, General

In the spirit of sharing knowledge that will save someone from the sort of tedious pain I went through the past couple days, here are a few Safari (2.0.4) bugs that I had to work around:

1. No Global Javascript eval() That's right. You can't eval() in the global (window) context. Safari doesn't allow it. A lot of places mention the fact that you can do a window.setTimeout, but that runs asynchronously (which I did not want). Thankfully, there is one place on the web that gives the secret sauce on how to implement something that will accomplish basically the same thing as eval() in any other browser. Wrap that up in a nice little function of your own, and you are good to go.

2. CSS: background-position and Container Size If you want to control the position of a background-image in a DIV, make sure that the DIV is at least one pixel larger than the background-image. Otherwise, your attempts to position it might drive you to the brink of insanity. Not that I would know.

3. Calling click() on a Checkbox If you think you can just grab a checkbox type INPUT element from the DOM and call click() on it, you are sorely mistaken! You must explicitly check that bad boy by doing something like checkElem.checked = true.

4. Reinitializing jQuery Interface Plugin Sortables This is probably the most esoteric gotcha of the bunch, as it involves a third-party library (jQuery). All of the other major browsers (Firefox 2, IE6/7, Opera 9) simply let you reinitialize as many Sortables as you want. You just call .Sortable(config) on any element each time you want to make it sortable. This does not work in Safari. Before you reinitialize the Sortable, you need to call .SortableDestroy() on it.

In the application I am working on, this is important because we load each new state via an XMLHTTPRequest. Now, when a Sortable is initialized, a callback is registered to handle the .SortableDestroy() before a new state is initialized.

That's That Hopefully this info will save some of you a little trouble.

cw