Click to See Complete Forum and Search --> : mozilla/ firefox detection


moondance
07-15-2004, 08:02 AM
I'm trying to adapt a rollover menu to work in firefox. The following code test for ie and netscape, but how do you check for mozilla?


f7_v4=(parseInt(navigator.appVersion)>=4 && parseInt(navigator.appVersion)<=5)?1:0
f7_ie=(document.all && f7_v4)?1:0
f7_ns=(document.layers && f7_v4)?1:0

Phil Karras
07-15-2004, 09:03 AM
The first thing to do is to see whay Mozilla returns for navigator.appVersion and build a test around that.

My version of Mozilla returns
"5.0 (Windows; en-US)"

Remember that NS is based on Mozilla so for most things whatever works for NS should work for Mozilla.

The fact is Mozilla follows the standards even better than NS does, you can check some of this on my web site listed below. Go with each browser and watch what happens when you roll over the different types of links.

IE changes some, NS, changes others, Mozilla, changes them all as intended.

Good-luck,

moondance
07-15-2004, 09:19 AM
i never knew ns used the mozilla engine :o , but thats just confused me a bit more now.

see i'm trying to adapt a rollover menu, and it should work for netscape, but dies when viewing in firefox, and as you say they both use the same engine, i'm not sure how to approach modifying the code to allow it to work in firefox.




//names of dropdowns stored here
f7_droplayer=new Array()
f7_droplayer[0]="drop1"
f7_droplayer[1]="drop2"
f7_droplayer[2]="drop3"
f7_droplayer[3]="drop4"
f7_droplayer[4]="drop5"
f7_droplayer[5]="drop6"

//simple browser check
f7_v4=(parseInt(navigator.appVersion)>=4 && parseInt(navigator.appVersion)<=5)?1:0
f7_ie=(document.all && f7_v4)?1:0
f7_ns=(document.layers && f7_v4)?1:0

/*
need to add mozilla firefox browsercheck
eg:
f7_ff=(document.firefox)?1:0
*/


//code for drops

function f7_showdrop(thelayer){
f7_keep=thelayer; f7_hideall(); f7_showitnow=1
f7_showit(thelayer)
}

function f7_showit(thelayer){
if(f7_ie){ eval(f7_droplayer[thelayer]+'.style.visibility="visible"') }
if(f7_ns){ eval('document.'+f7_droplayer[thelayer]+'.visibility="show"');}

/*
add mozilla showlayer

*/

}


function f7_hidedrop(){
f7_keep=-1; setTimeout('f7_hideall()',500)
}

f7_keep=-1

function f7_hideall(){
for(i=0;i<f7_droplayer.length;i++){
f7_hideit=0; f7_checkmousepos(i)

if(f7_ie && f7_keep!=i){
if(f7_hideit){ eval(f7_droplayer[i]+'.style.visibility="hidden"') }
}
if(f7_ns && f7_keep!=i){
if(f7_hideit){ eval('document.'+f7_droplayer[i]+'.visibility="hide"') }
}
}

/*
add mozilla hide layer
*/
}

//deal with cursor over layer
document.onmousemove = f7_getmousepos
if (f7_ns) document.captureEvents(Event.MOUSEMOVE)

function f7_getmousepos(e){
if(f7_ns){f7_mousex=e.pageX; f7_mousey=e.pageY}
if(f7_ie){f7_mousex=event.clientX; f7_mousey=event.clientY;}

//need to add check for mozilla mouseposition
/*
eg:
if(f7_ff){f7_mousex=firefox.X; f7_mousey=firefox.Y;}
*/
}

function f7_checkmousepos(i){
if(f7_ns){
f7_x_min=eval('document.'+f7_droplayer[i]+'.left')
f7_x_max=f7_x_min+eval('document.'+f7_droplayer[i]+'.clip.width')
f7_y_min=eval('document.'+f7_droplayer[i]+'.top')
f7_y_max=f7_y_min+eval('document.'+f7_droplayer[i]+'.clip.height')
}

if(f7_ie){
f7_x_min=eval(f7_droplayer[i]+'.style.pixelLeft')
f7_x_max=f7_x_min+eval(f7_droplayer[i]+'.scrollWidth')
f7_y_min=eval(f7_droplayer[i]+'.style.pixelTop')
f7_y_max=f7_y_min+eval(f7_droplayer[i]+'.scrollHeight')
}

//need to add mozilla firefox check here too


if (f7_mousex>=f7_x_min && f7_mousex<=f7_x_max && f7_mousey>=f7_y_min && f7_mousey<=f7_y_max){
f7_hideit=0; setTimeout('f7_hideall()',500)
}
else { f7_hideit=1 }
return f7_hideit
}


can you see where the code needs to modified?

thanks.

David Harrison
07-15-2004, 09:27 AM
Image rollover:

moondance
07-15-2004, 10:37 AM
ummm... i think you might've posted that attachment to the wrong thread? :confused:

David Harrison
07-15-2004, 04:12 PM
Sorry, I saw rollover and just thought "he wants an image rollover script". :D

If you want a good drop down menu then check out UDM4 (http://www.udm4.com/).
A menu is a list of links and should be marked up as such, then the JavaScript and CSS should be used to add fluff to it (ie: make it drop down).

Phil Karras
07-15-2004, 08:01 PM
see i'm trying to adapt a rollover menu, and it should work for netscape, but dies when viewing in firefox, and as you say they both use the same engine, i'm not sure how to approach modifying the code to allow it to work in firefox.

Sorry, I only just came across firefox today on my unix station so I can't really help with it not working there. Also, I really can't test things out on that box since it's NIH property.

Have you tried it just in Mozilla?

What do you mean by "it dies"?