Safari, AJAX and UTF8

written by benjamin on March 8th, 2007 @ 10:01 PM

The Lightbox-Popups we’re using did not work with Safari, at least until now. All UTF8 characters were broken, even though Firefox and IE7 were showing them correctly. Searching the web offers some standard solutions, however, we implemented our own few lines of code, as some of the solutions did not work the way we want. We’ve implemented a after_filter like that.

def add_utf8_header
  content_type = @headers["Content-Type"] || ( request.xhr? ? 'text/javascript' : 'text/html' )
  if /^text\//.match(content_type)
    @headers["Content-Type"] = "#{content_type}; charset=utf-8" 
  end
end

Right now it’s working fine with all major browsers. However, our first attempt – adding a AddDefaultCharset option to apache – did not work.

Post a comment

Options:

Size