Friday, November 03, 2006


I tried to control BUTTON size with relative size, like

BUTTON {display:block; text-align:center; width:2em; height:1.5em; padding:0;}

However, Safari give me a bigger size.
So, I tried to size down from javascript.

if (window.console) { //safari
document.writeln("<style type="'text/css'">");
document.writeln(".ccActions BUTTON {width:1.5em; height:1em;margin-bottom:2px;}");


Unfortunately, my Firefox 2 understood window.console. I
was surprised, but I didn't see it in the mozilla DOM reference.

But, I didn't have this problem in my new laptop's FF2. So, I looked at my extension. I disabled Firebug, then I found my script was good again.

So to be safe, I change my Safari condition as
if (window.console && window.console.log) //safari

Another Notes :
When I tried
if (window.console && window.console.log()) //safari
Safari crashed. Despite Safari is rarely crashed, but I still don't like.


Anonymous said...

Alex, object detection is only a good idea if you are testing for the object you are working with. If you actually need to test for errant behaviour, like the button size issue in this case, then a browser detect actually makes more sense.

I realise that it is usually a bad idea to do browser detects, but in this case that is effectively what you are already doing -- except that the detect you have chosen is an unreliable one; less reliable than the navigator object, that is.

console and console.log are not going to be removed from firebug -- and in future, other browsers or extensions may support debugging via this object, too. Frankly I would like to see that.

In any case, it is not good practice to script against browser difference by testing for a peripheral object that just happens to usually be there, in script space, at the same time as the behavior you are interested in. There are better ways.

Alex said...

I change the Safaro condition as

if (navigator.userAgent.indexOf("Safari")>0) { //safari

Firebug still pick up

if (window.console && window.console.log)

I still perfer to detect browser object as condition. String parsing is always more expensive.