posted
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?
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!
posted
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....
Posts: 1681 | Registered: Jun 2004
| IP: Logged |
posted
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.
Posts: 15770 | Registered: Dec 2001
| IP: Logged |