Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

X-Browser -> Why does Netscape ignore this code? 1

Status
Not open for further replies.

marybailey

Programmer
Mar 14, 2002
47
0
0
US
I picked up this code from the SuperFly site a long time back. Its supposed to &quot;genericize&quot; (I made this word up) DHTML using javascript to set variables to be used by either Netscape or IE. The layers are <div> definitions. It works for IE but it doesnt work for Netscape. Netscape just ignores it. Can someone tell me why? Also, is there a way to fix this so it does work?
Thanks,
Mrs B

function init(){
if (navigator.appName == &quot;Netscape&quot;) {
layerRef=&quot;document.layers&quot;;
styleSwitch=&quot;&quot;;
visibleVar=&quot;show&quot;;
}else{
layerRef=&quot;document.all&quot;; styleSwitch=&quot;.style&quot;; visibleVar=&quot;visible&quot;;
}
}

function showLayer(layerName){
eval(layerRef+'[&quot;'+layerName+'&quot;]'+styleSwitch+'.visibility=&quot;'+visibleVar+'&quot;');
}
function hideLayer(layerName){
eval(layerRef+'[&quot;'+layerName+'&quot;]'+styleSwitch+'.visibility=&quot;hidden&quot;');
}
 
The following code would be a bit nicer: It'd work in Gecko browsers too, and it'd be more efficient:
Code:
get=document.all?document.all:
document.layers?function(d,l,_,i) {
 if (!l) l=window;
 l=l.document;
 if (_=l[d])
  if (_==l.applets[d]) return _;
  else return _.style=_;
 if (_=l.links[d])
  return _.style=_;
 for (i = 0,l=l.layers; i < l.length; i++)
  if (_=get(d,l[i])) return _;
}:
function(d) {return document.getElementById(d) || document.getElementsByName(d);};

function showLayer(layerName) {get(layerName).style.visibility=&quot;visible&quot;;}
function hideLayer(layerName) {get(layerName).style.visibility=&quot;hidden&quot;;}




But anyway, as for the code you had, there are two possible reasons: Your version of Netscape is old (older than 4.7), or your DIV is statically positioned. Netscape 4 accepted DIV and SPAN elements only if they were absolutely or relatively positioned (
Code:
style=&quot;position:absolute;&quot;
or
Code:
style=&quot;position:relative&quot;
).
Code:
- UNIMENT
 
Your version worked like a charm. Your reason it didnt work is true too.
Thanks for sharing your knowledge!
Mrs B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top