This is topic Is anyone a JavaScript guru?? in forum Books, Films, Food and Culture at Hatrack River Forum.


To visit this topic, use this URL:
http://www.hatrack.com/ubb/main/ultimatebb.php?ubb=get_topic;f=2;t=027553

Posted by Zeugma (Member # 6636) on :
 
I found some code online for making a neat JS menu tree, and it's working great. Unfortunately, something about it brings IEwin to its knees. Does anyone know what's wrong with this?

code:
<script language=JavaScript>

function checkBrowser(){
this.ver=navigator.appVersion
this.dom=document.getElementById?1:0
this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
this.ie4=(document.all && !this.dom)?1:0;
this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
this.ns4=(document.layers && !this.dom)?1:0;
this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
return this
}
bw=new checkBrowser()

function showhide(div,nest){
obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
if(obj.display=='block' || obj.display=='block') obj.display='none'
else obj.display='block'
}

function show(div,nest){
obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
obj.display='block'
}

function hide(div,nest){
obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
obj.display='none'
}
</SCRIPT>

IE says the error is on the last function, something about needing an object to be declared. Then it crashes. Oi!

Thanks!
 
Posted by King of Men (Member # 6684) on :
 
I know nothing about Javascript, but that is a truly horrible coding style. [Smile]
 
Posted by Zeugma (Member # 6636) on :
 
Yeah, and I really don't think I need all this browser check stuff, anyhow. The site isn't going to work in older browsers either way. But I don't know enough JS to know what I can safely remove from the show/hide code.... [Frown]
 
Posted by Zeugma (Member # 6636) on :
 
ba-da-bump?

[Smile]
 
Posted by fugu13 (Member # 2859) on :
 
As stated, the coding style is really atrocious, making it hard to decipher.

If you don't need it to degrade gracefully, I think you can just modify the last function to be as follows:

code:
function hide(div,nest){
obj=document.getElementById(div).style
obj.display='none'
}

You may need to modify show similarly

code:
function show(div, nest){
obj=document.getElementById(div).style
obj.display='block'
}

and possibly showhide

code:
function showhide(div,nest){
obj=document.getElementById(div).style
if(obj.display=='block' || obj.display=='block') obj.display='none'
else obj.display='block'
}

The above code has a part that says essentially "if a or a", which seems silly, but since it shouldn't hurt anything and there may be some silly reason, I left it in.

Modify each function to what I show only if IE says its having problems with it (well, modifying them all shouldn't hurt, but its worth tracking down which one(s) IE had an issue with).

The code should work in all modern browsers.
 
Posted by Zeugma (Member # 6636) on :
 
Thanks a lot, fugu! That's just what I needed. [Smile]
 
Posted by fugu13 (Member # 2859) on :
 
np, glad I could help.
 


Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2