So it never fails; I get a website up and running perfectly on Firefox and IE only to find that it is broken in Safari. After playing with the CSS for a while I’ve found that there isn’t much I can do. It has to do with some absolute(ly) positioned divisions and the background not stretching to fit. Im probably going to make another CSS file specifically for Safari machines, seeing as how Safari bugs have bit me at the worst times (like in an interview). I’ve been messing with JavaScript all night long and finally found a very easy way to detect Safari here:
http://dithered.chadlindstrom.ca/javascript/browser_detect/index.html
The specific browser type is combined with other browser information in the .userAgent variable, so you have to write some script to search through it. Its easier than it sounds. Here is the code:
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('safari/') != -1){
alert("You're using Safari, moron!")
}
Told ya! Substitute ’safari’ for whatever you need to identify.
Edit - This script searches through the user agent string. Visit this site to find strings for the browser you are trying to identify.
you are going about this backwards btw. what the hell would ever program a site to look good in IE first and then move to safari.
Thanks a lot..this works.. but i couldn’t use it for IE. Infact when u use this from Chrome it takes the safari keyword, instead of chrome
Thanks for the comment. I’ve been looking into other options with PHP, which I hope will work for everything. I find it strange that it recognizes Chrome when using the Safari keyword. I wonder if this is related in any way to WebKit.
As far as IE, you may want to try some different keywords, such as “ie 5″ I find this works in some cases. I’ll post a PHP solution in a bit; it might work a bit better than this option.
**EDIT**
Here is your answer. In the user agent string a lot of browsers identify themselves with the engine you use and the browser they’re like. Here is Chrome:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13You’ll see that Safari is part of the string. A possible solution may be to find something specific to the Safari string and go with that. UA strings can be found here.
@brian
Once you start getting involved with a lot of JavaScript and frameworks you’ll find lots of holes in CSS that at the very least will make the site non-compliant with W3C standards. At worst they’ll work in all but one browser. In this case, it was Safari.
I definitely agree with @brian. Safari has given me problems all times, almost nothing works with it if you use javascript.
Regards