2011-07-20 50 views
1
  1. if (document.all)
  2. document.body.style.behavior='url(#default#homepage)';
  3. if (window.sidebar)

什么是那些在javascript意思线?谢谢。javascript中的行含义是什么?

+0

请忽略第一个:) – Ibu

+0

嗨,你应该提供一个更大的摘录代码的答案是非常有用的。 – ocodo

+3

我觉得这个编辑不正确 – Ibu

回答

2

不要使用的document.all:

if (document.all) { 
    element = document.all[id]; 
else { 
    element = document.getElementById(id); 
} 
  1. 的document.all是在Internet Explorer 4中引入的,因为W3C DOM还没有标准化抓住引用的方式到使用其ID的元素。
    当IE 5出来时,document.getElementById()已经标准化,因此IE 5包含了对它的支持。 More info here.

  2. document.body.style.behavior='url(#default#homepage)'用于将当前页面设置为IE中的主页。

  3. if (window.sidebar)是用于Firefox
+0

谢谢。以下几行是什么意思? – zhuanzhou

+0

@zhuanzhou这是解释,为什么以及何时这张支票走进了世界。 – VMAtm

+0

谢谢,明白了。这条线的含义是什么? document.body.style.behavior = 'URL(#默认#主页)'; – zhuanzhou

2
document.all is used to check if the browser is IE 
2

if (document.all):用来检查布劳尔是IE,但请注意,这是因为bad practice它不再做测试的一个好方法。

if (window.sidebar):测试浏览器是否为Firefox。

编辑:document.body.style.behavior='url(#default#homepage)';最有可能使用to set the homepage when the browser is IE。但是,it does not seem to work well with Firefox and the others

+0

明白了,谢谢,waht的这句话的意思是? document.body.style.behavior = 'URL(#默认#主页)'; – zhuanzhou

1
声明

1名试图检测该浏览器是IE和语句2使用的IE-仅API检查:behavior property

但是,document.all不是IE专用功能。它也存在于Chromium/Chrome和其他基于WebKit的浏览器上。

因此,语句1通过IE & Chrome传递,但语句2仅适用于IE。