> I want to test if the browser is ie or firefox and then set the width
> and height of a thickbox differently depending on this.  Is this
> considered bad practice and if so how might you do it better?

If you're setting the width/height based on interface factors such as
the width of the scrollbars cutting into the reported page area then
detecting browsers specifically is probably the only way to do it. BTW
using this method is likely to cause problems in other browsers you
haven't thought of (Opera, Safari, Konqueror, dozens more) so you
should always have a default option. And of course the thing you
assume for IE may not always be true.

If you're detecting browsers so that you can use different width/
height functions then there shouldn't be a need - the best practice
here is to test *if* the object/function exists. Here's the code from
another jquery thickbox script that gets the width/height of available
content area; you can then base your set width/height off these.

var de = document.documentElement;
var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth)
|| document.body.clientWidth;
var h = window.innerHeight || self.innerHeight ||
(de&&de.clientHeight) || document.body.clientHeight;

I guess the main question is, why do you need to specifically detect
IE vs Firefox? And will your script also work if your assumptions
based on the browsers are not true?

Reply via email to