Логин:

Пароль:

Форумы
Общие вопросы
Document Object Model
Обсуждаем конференцию
Web Usability (test)

Общие вопросы

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. А Может, Проще По-Русски?
СообщениеАвторДата
RaD27.03.2003 11:18
Maniac27.03.2003 11:55
Leechy27.03.2003 15:34
Maniac27.03.2003 16:47
RaD27.03.2003 13:47
Maniac27.03.2003 14:05
п?п?я?я?я?28.03.2003 08:33
Maniac28.03.2003 10:03