views:

6193

answers:

5

I need to change a value based on each browser since they all render differently.

if (navigator.appName == 'Netscape'){
  top = 17;
}

This was working but unfortunately both Firefox and Safari show up as "Netscape"

How would I use jQuery 1.3.2 to detect all these? I couldn't find any info under jquery.support now that jquery.browser is gone.

Thanks!

+1  A: 

What are they rendering differently? Is there a way you can use capability detection rather than browser sniffing? It's less prone to breakage when new browsers come along, and more tolerant of the fringe.

DDaviesBrackett
I've had a couple weird cases where capability detection didn't help me. One was in Opera, where there was a bug in the canvas drawing that caused filled charts in flot to not render correctly until the bug was fixed. I couldn't think of anything better to do than to check for Opera, then check for the version where the bug was fixed. For older versions of Opera, I drew the chart unfilled, which was less pleasing, but at least not buggy.
Nosredna
@Nosredna Feature detection is **not a panacea**. It's simply a more sensible approach to cross-browser scripting. The problem is that people use browser sniffing when feature detection is just as trivial (or only slightly more complex) to implement, effectively shooting themselves in the foot. There are obviously cases when detection is helpless (e.g. purely visual discrepancies). The idea is to understand unreliability and fragile nature of browser sniffing and apply it with care and understanding, not follow some rules blindly.
kangax
A: 

They all renders the tooltip's top css value differently.

var container = $('<div id="personPopupContainer">'
 + '<div id="personPopupContent">'
 + '</div>'
    + '</div>');

var pos = $(this).offset();
var width = $(this).width();
var reposition = { left: (pos.left - width) + 'px', top: pos.top + msg + 'px' };

container.css({
                    top: reposition.top
             });
novon
Elaborating on your question is best done as an edit to the question itself. It's OK to actually answer your own question, however, if you figure out the answer. People may vote you down for this. However, I notice you are new here, and you might not have enough cred to edit your question. Do you have an "edit" link to the left of your avatar at the bottom of your question?
Nosredna
@Nosredna, I thought you could edit your own post no matter how low your rep is?
alex
I thought that happened to me on my first day. maybe I just didn't know what I was doing. :-)
Nosredna
+3  A: 

Are you, or have you considered, using a reset.css stylesheet to set all browsers' defaults to zero? If not I recommend you do so since it might solve your current problem, as well as potential future ones.

It may help because it would set all browsers to a baseline zero, so when you apply padding or positioning, it should have the same effect in all browsers.

Dan Herbert
reset.css is evil
Max Toro
@Max Care to elaborate on why? I find it rare that anyone designs sites without a reset style sheet in some form these days.
Dan Herbert
i agree, some elaboration as to why it's evil would be awesome.
kdawg
+3  A: 

If you must have browser detection (despite the warnings against it), ppk's routine is current (even up through Chrome and iPhone).

Nosredna
+1  A: 

you can use the jQuery.browser object. It's deprecated in jQ 1.3 in favour of the jQuery.support, but there's no immediate plans to remove it altogether, so you should be safe.

That said, using browser sniffing, while very easy and tempting, isn't usually the best way to do things. Since it sounds like you're having problems with some browsers doing CSS differently, you might want to look at jQuery.support.boxModel.

nickf
jQuery.browser thinks my Chrome is Safari. ppk's knows better. Yet another way browser detection can go wrong. :-)
Nosredna