if (document.all)
document.body.style.behavior='url(#default#homepage)';
if (window.sidebar)
What's those lines meaning in javascript? thank you.
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 .
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 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.