what's the line meaning in javascript?
if (document.all)
document.body.style.behavior='url(#default#homepage)';
开发者_开发问答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);
}
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..document.body.style.behavior='url(#default#homepage)'
is used to set current page as home page in the IE.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.
精彩评论