Netscape 4.x兼容性问题 [英] Netscape 4.x Compatibility Issue

查看:59
本文介绍了Netscape 4.x兼容性问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个使用以下行的函数:


var level = document.getElementById(id);


我也知道我要找的元素的名称。在Netscape

Communicator 4.7中,然而,这不起作用......我该怎么做才能在这个浏览器中获得相同的元素?谢谢!


Jon

Hi,

I have a function that uses the following line:

var level = document.getElementById( id);

I also know the name of the element I am looking for. In Netscape
Communicator 4.7, however, this doesn''t work... What can I do to get
the same element in this browser? Thanks!

Jon

推荐答案

Jon写道:
var level = document.getElementById(id);
我也知道我要找的元素的名称。然而,在Netscape
Communicator 4.7中,这不起作用......我该怎么做才能在这个浏览器中获得相同的元素?谢谢!
var level = document.getElementById( id);
I also know the name of the element I am looking for. In Netscape
Communicator 4.7, however, this doesn''t work... What can I do to get
the same element in this browser? Thanks!




由于netscape 4.x不支持getElementById(),它变得复杂。

你是什么类型的元素试图获得这个位置?


我写了这个小型库以获得< a>的位置

Netscape4.x支持的元素。它并不总是很漂亮,但是如果你可以在某处放置一个< a>

标签并将其用作参考,它允许定位对象

相对于< a>在netscape4:
http://www.javascripttoolbox.com/anchorposition/


-

Matt Kruse

Javascript工具箱: http://www.JavascriptToolbox.com/


Jon写道:
Jon wrote:


我有一个使用以下行的函数:

var level = document.getElementById(id);

我也知道我要找的元素的名称。然而,在Netscape
Communicator 4.7中,这不起作用......我该怎么做才能在这个浏览器中获得相同的元素?谢谢!

Jon
Hi,

I have a function that uses the following line:

var level = document.getElementById( id);

I also know the name of the element I am looking for. In Netscape
Communicator 4.7, however, this doesn''t work... What can I do to get
the same element in this browser? Thanks!

Jon



Jon,


Netscape 4(以及大多数其他旧版浏览器)不支持

使用getElementById()或者,事实上,现代的其他大部分都是b $ b DOM。 向后兼容是指向后兼容。当然,东西很好,但不是新的东西。


所以,简而言之,你需要问问自己你想要多少钱

支持这些旧版浏览器。值得努力吗?要求您的用户升级到现代浏览器会更容易吗?
?该问题影响了多少用户?b $ b?如果你发现你确实需要支持这些旧的浏览器,那么肯定可以使用旧版本的

代码来执行相同或相似的操作 - 但对于显而易见的原因

这意味着您将难以维护代码并且需要测试软件。


Jon,

Netscape 4 (along with most other older browsers) does not support the
use of "getElementById()" or, in fact, most of the rest of the modern
DOM either. The "backward-compatible" stuff, of course, is fine but not
the newer stuff.

So, in a nutshell, you need to ask yourself just how much you want to
support these older browsers. Is it worth the effort? Would it be easier
to ask your users to upgrade to modern browsers? How many users are
affected by the problem? If you find you really do need to support these
older browsers then it is certainly possible to use older versions of
code that will do the same or similar things - but for obvious reasons
that means you will have a much harder time maintaining the code and
testing the software.


2004年6月15日07:27:08 -0700,Jon< jm ***** @ jonathanludwig.com>写道:
On 15 Jun 2004 07:27:08 -0700, Jon <jm*****@jonathanludwig.com> wrote:


我有一个使用以下行的函数:

var level = document.getElementById(id );

我也知道我要找的元素的名称。然而,在Netscape
Communicator 4.7中,这不起作用......我该怎么做才能在这个浏览器中获得相同的元素?谢谢!

Jon
Hi,

I have a function that uses the following line:

var level = document.getElementById( id);

I also know the name of the element I am looking for. In Netscape
Communicator 4.7, however, this doesn''t work... What can I do to get
the same element in this browser? Thanks!

Jon




你好Jon,


马特和马克都发表了好主意。


以下内容来自X图书馆,获得LGPL许可( http://cross-browser.com/)。你不必使用图书馆,但这应该给你一些想法。


函数xGetElementById(e)

{

if(typeof(e)!=''string'')return e;

if(document.getElementById)e = document.getElementById(e);

否则if(document.all)e = document.all [e];

else if(document.layers)e = xLayer(e);

else e = null;

返回e;

}

函数xLayer(id,root)

{

var i,layer,found = null;

if(!root)root = window;

for(i = 0; i< root.document。 layers.length; i ++){

layer = root.document.layers [i];

if(layer.id == id)return layer;

if(layer.document.layers.length)found = xLayer(id,layer);

if(found)return found;

}

返回null;

}



Hi Jon,

Matt and Mark have both posted good ideas.

The following is from the X Library, licensed LGPL (http://cross-browser.com/). You don''t have to use the library, but this should give you some ideas.

function xGetElementById(e)
{
if(typeof(e)!=''string'') return e;
if(document.getElementById) e=document.getElementById(e);
else if(document.all) e=document.all[e];
else if(document.layers) e=xLayer(e);
else e=null;
return e;
}
function xLayer(id,root)
{
var i,layer,found=null;
if (!root) root=window;
for(i=0; i<root.document.layers.length; i++) {
layer=root.document.layers[i];
if(layer.id==id) return layer;
if(layer.document.layers.length) found=xLayer(id,layer);
if(found) return found;
}
return null;
}


这篇关于Netscape 4.x兼容性问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆