Hi,
I'm trying to display different layers depending on what browser the user is using. I have one Javascript Function that shows/hides a layer and another which detects the bowser type and then is supposed to call the JS layer function accordingly. Needless to say, I havn't really got a clue what to edit and can't figure it out. If anyone could have a look at the code I'm using below and show me what it should look like I would be most gratefull.
Thanks for your time.
---------
THE CODE:
---------
This is the script that toggles the layers between visible and hidden:
<script language="JavaScript">
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?")>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && d.getElementById) x=d.getElementById; return x;
}
function MM_showHideLayers() { //v3.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible'v='hide')?'hidden':v; }
obj.visibility=v; }
}
//-->
</script>
This is the script I have mangled in the process of trying to get it to call the layer script according to the users browser type. I have no idea how to call Javascript function from within another Javascript function, this is my first hurdle. Please help!
<script language="JavaScript">
var browser_type=navigator.appName
var browser_version=parseInt(navigator.appVersion)
//if NS 6
if (browser_type=="Netscape"&&browser_version>=5)
eval ('MM_showHideLayers('NS6','','show')') &&
eval ('MM_showHideLayers('NS4','','hide')') &&
eval ('MM_showHideLayers('IE','','hide')');
//if IE 4+
else if (browser_type=="Microsoft Internet Explorer"&&browser_version>=4)
eval ('MM_showHideLayers('NS6','','hide')') &&
eval ('MM_showHideLayers('NS4','','hide')') &&
eval ('MM_showHideLayers('IE','','show')');
//if NS4+
else if (browser_type=="Netscape"&&browser_version>=4)
eval ('MM_showHideLayers('NS6','','hide')') &&
eval ('MM_showHideLayers('NS4','','show')') &&
eval ('MM_showHideLayers('IE','','hide')');
//Default action to take (NOT NS 4+ and NOT IE 4+)
else
eval ('MM_showHideLayers('NS6','','hide')')&&
eval ('MM_showHideLayers('NS4','','hide')')&&
eval ('MM_showHideLayers('IE','','show')');
</script>
I'm trying to display different layers depending on what browser the user is using. I have one Javascript Function that shows/hides a layer and another which detects the bowser type and then is supposed to call the JS layer function accordingly. Needless to say, I havn't really got a clue what to edit and can't figure it out. If anyone could have a look at the code I'm using below and show me what it should look like I would be most gratefull.
Thanks for your time.
---------
THE CODE:
---------
This is the script that toggles the layers between visible and hidden:
<script language="JavaScript">
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?")>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && d.getElementById) x=d.getElementById; return x;
}
function MM_showHideLayers() { //v3.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible'v='hide')?'hidden':v; }
obj.visibility=v; }
}
//-->
</script>
This is the script I have mangled in the process of trying to get it to call the layer script according to the users browser type. I have no idea how to call Javascript function from within another Javascript function, this is my first hurdle. Please help!
<script language="JavaScript">
var browser_type=navigator.appName
var browser_version=parseInt(navigator.appVersion)
//if NS 6
if (browser_type=="Netscape"&&browser_version>=5)
eval ('MM_showHideLayers('NS6','','show')') &&
eval ('MM_showHideLayers('NS4','','hide')') &&
eval ('MM_showHideLayers('IE','','hide')');
//if IE 4+
else if (browser_type=="Microsoft Internet Explorer"&&browser_version>=4)
eval ('MM_showHideLayers('NS6','','hide')') &&
eval ('MM_showHideLayers('NS4','','hide')') &&
eval ('MM_showHideLayers('IE','','show')');
//if NS4+
else if (browser_type=="Netscape"&&browser_version>=4)
eval ('MM_showHideLayers('NS6','','hide')') &&
eval ('MM_showHideLayers('NS4','','show')') &&
eval ('MM_showHideLayers('IE','','hide')');
//Default action to take (NOT NS 4+ and NOT IE 4+)
else
eval ('MM_showHideLayers('NS6','','hide')')&&
eval ('MM_showHideLayers('NS4','','hide')')&&
eval ('MM_showHideLayers('IE','','show')');
</script>