JS and style with Mozilla> return (isNN4) ? document.layers[id] : > (isIE) ? document.all[id].style : > (isNN6) ? document[id] : > (isDOM) ? document.getElementById(id).style : 0;
> But it doesn't work with Mozilla 1.3. > Any ideas?
First Of All There Can Be Few Ideas Until We Don't Know How Exactly You Determine Those isXX Variables. However Supposing That They Are Correctly Sniffed The Problem Is Here:
(isNN6) ? document[id] : (isDOM) ? document.getElementById(id).style : 0;
Netscape 6, 7, Mozilla And All Gecko-Based Browsers Do Not Have Anything Like 'document[]' (AFAIK). They All Operate On Standard DOM Interfaces, i.e. document.getElementById. In Fact Even Most IE Versions (Win 5, 5.5, 6 And All Mac) Also Work This Way. So The Quickest Hack To Make Your Code Work Is Just Eliminate The Strange isNN6 Thing:
> return (isNN4) ? document.layers[id] : > (isIE) ? document.all[id].style : > (isDOM) ? document.getElementById(id).style : 0;
But Anyway Browser-Based Sniffing Is A Bad Idea In Its Origin. It Is Much Simpler And More Reliable To Sniff For Feature, Not User Agent. Like This:
try{ return document.getElementById(id).style; } catch(E) { try{ return document.all[id]; } catch(E) { return document.layers[id]; }//try }//try
Note That This Code Works By Itself Without Any Sniffings Before. I Also Suggest To Get Rid Of NN4 Fallback Since This Old Browser Largely Just Can't Alter Styles In A Document After Loading:
try{ return document.getElementById(id).style; } catch(E) { return document.all[id]; }//try
P.S. А Может, Проще По-Русски? |