Safari Gotchas

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

5 Responses to “Safari Gotchas”

  1. rob hawkins Says:

    Thanks! bookmarked

  2. Joseph Says:

    I am glad that you post this kind of stuff, save the unsuspecting IT guy! And it makes me happy when I read that others come across many web authoring problems as well…I know I’m not alone.

  3. Dan Wolfe Says:

    So, I know this isn’t really a comment on what was said above… But I found this link, and wanted to pass it on.

    http://cubegames.net/downloads/python.php

    It lets you take your python projects with and work on then from a flash drive, and doesn’t leave any traces in the registry or temp files behind…

    It’s on the page of one of the main PortableApps.com developers, so I’m sure it’s legit. And I’m sure you’ve already seen it… I just thought I’d pass it on in case you hadn’t.

    Anyway, that’s about it. Thought I’d pass it on.

  4. Mark Rowe Says:

    The first three issues you describe are:
    http://bugs.webkit.org/show_bug.cgi?id=11399
    http://bugs.webkit.org/show_bug.cgi?id=3998
    http://bugs.webkit.org/show_bug.cgi?id=7881

    All have been fixed in WebKit nightly builds and I would expect the fixes to be present in Safari 3.0 when that is released.

  5. christian Says:

    Mark - thanks for the response. The Safari 3.0 alpha (or is it beta?) release does seem much improved over 2.x. Nice work!

Leave a Reply