Re: opacity



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
.



Relevant Pages

  • Re: e.onmousedown= funciton () { return !1; };
    ... likely that every document will be created with head and body elements ... immediately available for any a script that exists in a valid "normal" ... without waiting for onload or "ready" function. ... when higher level code wants to use that low-level code, ...
    (comp.lang.javascript)
  • Re: Is there a correct place to put javascript within a html file?
    ... The HTML specification tells you where script elements are permitted: ... script files have downloaded and if they're all in the head ... ... like the sensible thing to do; at least there's a reason for it. ... javascript is positioned just before the then the various html ...
    (comp.lang.javascript)
  • Re: dynamisches Nachladen von js und webkit mobile
    ... `head', welches allenfalls den Rest nachlädt und gut ist. ... referenzierte Script zusammenbauen. ... Besser die Deklaration weglassen, sie triggert gern den Compatibility Mode ... IE 6-8 würde mit xhtml+xml die seite eh downloaden und gar nicht ...
    (de.comp.lang.javascript)
  • Re: my if comands are still not working. please help
    ... but you're over my head. ... function showorders() { ... alert("start of show orders script"); ... the file is not a htm, html file it is a .js file that is called from a htm file that has ...
    (microsoft.public.frontpage.programming)
  • Re: e.onmousedown= funciton () { return !1; };
    ... likely that every document will be created with head and body elements ... The window, document, document.documentElement properties are immediately available for any a script that exists in a valid "normal" page. ... Not including the scripts in the head also allows the script access to document.body, without waiting for onload or "ready" function. ... However, requiring low level code to exist in the body can cause inconvenience when higher level code wants to use that low-level code, but that higher level code wants to exist in the head ). ...
    (comp.lang.javascript)