Re: opacity
- From: Peter Michaux <petermichaux@xxxxxxxxx>
- Date: Thu, 6 Dec 2007 23:06:05 -0800 (PST)
On Dec 6, 2:44 pm, David Mark <dmark.cins...@xxxxxxxxx> wrote:
On Dec 6, 2:37 pm, Peter Michaux <petermich...@xxxxxxxxx> wrote:
[snip]
How about this...
if (typeof document != 'undefined') {
var getHtmlElement = function(docNode) {
return (docNode || document).documentElement;
};
}
Testing in IE4 with the document.all fallback showed some problems.
While the script is running in the head
document.all[0] // !
document.all[1] // HEAD
after the window.onload event
document.all[0] // !
document.all[1] // HTML
That seems to make it impossible to use the html element to check for
the style object while head scripts are evaluated. However it is just
as easy to use the head element to check for the style object. I
prefer to do feature tests in the head as the code is first evaluated
if possible. An entire Ajax library can be feature tested in the head
but we need one element for form serialization to check for the
attributes property.
The only change this requires is changing the name from
"getHtmlElement" to "getAnElement" which actually make makes more
semantic sense. It isn't really that we want the documentElement in
particular but we just need some element to test.
Here are the two versions I have. The second one could be a bit more
elegant so toLowerCase is called only once. I just wanted to post that
this change is necessary and get any feedback about the change in
general.
// -------------------------------------
if (typeof document != 'undefined' &&
document.documentElement) {
var getAnElement = function(d) {
return (d || document).documentElement;
};
}
// -------------------------------------
// (I know I went a bit extreme on the short identifiers)
if (typeof document != 'undefined') {
var getAnElement = (function() {
function f(d) {
d = d || document;
var g = 'getElementsByTagName',
t = d.documentElement ||
// The following line doesn't seem to add any benefit
// in any of the tested browsers.
// ((t=d.all) && t.tags && (t=t.tags('html')) && t[0])
||
(d[g] && d[g]('html')[0]);
if (!t && d.all && (t=d.all[0])) {
t = d.all[(t.tagName == '!')?1:0] || null;
if (t &&
t.tagName.toLowerCase() != 'html' &&
// for during load in IE4
t.tagName.toLowerCase() != 'head') {
t = null;
}
}
return t;
};
if (f()) {
return f;
}
})();
}
// -------------------------------
Peter
.
- Follow-Ups:
- Re: opacity
- From: David Mark
- Re: opacity
- References:
- Re: opacity
- From: dmark
- Re: opacity
- From: Peter Michaux
- Re: opacity
- From: Peter Michaux
- Re: opacity
- From: David Mark
- Re: opacity
- From: Peter Michaux
- Re: opacity
- From: David Mark
- Re: opacity
- Prev by Date: Re: window.clearTimeout problem?
- Next by Date: Re: window.clearTimeout problem?
- Previous by thread: Re: opacity
- Next by thread: Re: opacity
- Index(es):
Relevant Pages
|