开发者

what's the line meaning in javascript?

开发者 https://www.devze.com 2023-03-21 07:36 出处:网络
if (document.all) document.body.style.behavior=\'url(#default#homepage)\';开发者_开发问答 if (window.sidebar)
  1. if (document.all)
  2. document.body.style.behavior='url(#default#homepage)';开发者_开发问答
  3. if (window.sidebar)

What's those lines meaning in javascript? thank you.


Don’t use document.all:

if (document.all) {
   element = document.all[id];
else {
   element = document.getElementById(id);
}
  1. document.all was introduced in Internet Explorer 4, because the W3C DOM hadn’t yet standardised a way of grabbing references to elements using their ID.
    By the time IE 5 came out, document.getElementById() had been standardised and as a result, IE 5 included support for it. More info here..

  2. document.body.style.behavior='url(#default#homepage)' is used to set current page as home page in the IE.

  3. if (window.sidebar) is a check for firefox


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


if (document.all): used to check if the brower is IE, but note this is bad practice because it is no longer a good method of doing the test.

if (window.sidebar): test if the browser is Firefox.

EDIT: document.body.style.behavior='url(#default#homepage)'; is most likely used to set the homepage when the browser is IE. However, it does not seem to work well with Firefox and the others.


Statement 1 tries to detect if the browser is IE and statement 2 uses an IE-only API: behavior property.

However, document.all is not IE-only feature. It also exists on Chromium/Chrome and other WebKit based browsers.

Therefore, statement 1 get passed on IE & Chrome, but statement 2 only works on IE.

0

精彩评论

暂无评论...
验证码 换一张
取 消