View Full Version : Floating help

Nov 21st, 2009, 03:01 AM
I have this var set:

var floatingMenu =
targetX: -270,
targetY: 13,

hasInner: typeof(window.innerWidth) == 'number',
hasElement: document.documentElement
&& document.documentElement.clientWidth,

? document.getElementById(floatingMenuId)
: document.all
? document.all[floatingMenuId]
: document.layers[floatingMenuId]

I want the number to be assigned to targetX (the red part) to be different for Firefox, Chrome or Internet Explorer. How do i do that?

Old Pedant
Nov 21st, 2009, 03:39 AM
Well, for starters, you don't use document.getElementById as a test. That hasn't worked since the days of MSIE version 4.

Any code you see that is using document.all is to be avoided as being way way way obsolete.

And same for document.layers which was relavent to only Netscape version 4.

So you can reduce that to just:

menu: document.getElementById(floatingMenuId);
and there's no browser in current use where that won't work.

As to detecting the browser: There are a ton of scripts out there that will tell you down to the version what browser you are on. Google for them.

This may be one of the best:
But read his advice: DO NOT detect the browser. Instead, detect what it supports.