PDA

View Full Version : NS4 detection


AndyB
06-26-2002, 02:14 AM
Apologies for such a simple request, but my brain's fried.

I need a javascript snippet that will detect NS4 exclusively and set a variable to 1 else set it to 2

x_goose_x
06-26-2002, 02:42 AM
Try searching you'll usually find somethinf similar:

http://www.dynamicdrive.com/dynamicindex9/bredirect.htm

which you can mod to do what you want:

<script>
var browser_type=navigator.appName
var browser_version=parseInt(navigator.appVersion)
//if NS4+
if (browser_type=="Netscape"&&browser_version>=4) {
myvar = 1;
}
//If NOT NS4+
else {
myvar = 2;
}
</script>

jkd
06-26-2002, 05:44 PM
Object detection is good in a pinch, but what if another script defines document.layers before the detection?

For example, I am the project owner of http://layeremu.mozdev.org

Which emulates everything to do with layers in Gecko. This includes defined document.layers as an array (collection).

After applying this to a page:

typeof document.layers != 'undefined'

suddenly is true in NS4 AND NS6, NS7, Mozilla, K-meleon, Galeon, Beonex, etc - whatever Gecko browser they may be using.

Just some food for thought. :)

brothercake
06-26-2002, 08:40 PM
But shurely that doesn't matter since it will still work inside your emulator ... except that ns6 will be running the ns4 code instead of the (probably more attractive and powerful) gecko code ... :rolleyes:

just a thought. I've found object detection like that is only reliable if its done in the BODY section

jkd
06-27-2002, 12:47 AM
Originally posted by brothercake
But shurely that doesn't matter since it will still work inside your emulator ... except that ns6 will be running the ns4 code instead of the (probably more attractive and powerful) gecko code ... :rolleyes:

Maybe and yes. :D

Its hard to get perfect emulation ;) - I'm still struggling with getting the clip properties all working, and siblingAbove/siblingBelow seem to currently have unpredictable behavior ;).
I do have a draggable layer example though that works perfect in Gecko using NS4 layers.

Anyway, I haven't run across your problem with object detection outside of the HTMLBodyElement yet, but then again lately I've only been writing stuff for Mozilla, and there are currently plenty of ways of having Mozilla see code that other browsers can't.
(Such as language="Javascript1.5" in the script tag, or through a binding, etc).

The only time I have something against object detection though is when it is actually used to determine the browser - I regularly use object detection to see if say an element supports addEventListener, but never use that check to determine that the browser is Gecko (Though I think Konqueror may also support addEventListener - probably mistaken though).

:)

Zvona
06-27-2002, 09:03 AM
I use always object detection. Reason is that I don't need to know what browser user has, but I need to know how to refer document's objects.

For example, I don't care if someone emulates document.all hierarchy, as long as I can refer to objects with document.all[objectId].