Re: Dynamic select lists using optgroups again - without frameworks



RobG wrote:
[...] Thomas 'PointedEars' Lahn [...] wrote:
RobG wrote:
It has been mentioned here a number of times that you can achieve the
same effect as a "dom ready" function by inserting all your scripts
just before the closing </body> tab, then calling your initialising
function at the bottom of the last script element, or as the only code
in the last script element.
The DOM will be ready and you don't need to use window.onload (or
document.body or whatever) or DOM ready and it has the pleasant side
effect of loading the page faster.
However, the functionality of this approach is based on mere assumption,
much in contrast to the intrinsic `onload' event handler attribute.

Using onload is also based on the "mere assumption" that the UA
supports onload. If you feature detect for onload and find it's not
supported, what then?

You are confusing the proprietary event handler property, and the
standardized intrinsic event handler attribute as specified in HTML 4.01 and
universally supported long before that. (It is easy and appropriate to say
that because for Web developers there were only two user agents to consider
at the time the feature was introduced, Netscape Navigator and Microsoft
Internet Explorer; in order to keep up with the competition, their features
were readily implemented by other vendors, including the `onload' attribute.
Which eventually led to its inclusion in HTML 4 as being an apparently
universally supported feature that therefore deserved to be standardized.)

I recommended using the latter one.

I imagine that scenarios is about as common as finding that the DOM
isn't ready when the very last element is parsed.

Apples, oranges. There is exactly *nothing* in any public specification
that says that the document tree would be fully accessible with all
specified properties and methods before the `load' event of the document
occurs. Your suggestion is (naturally) merely based on observation in a
subset of user agents, and the jump to the conclusion that therefore it must
be so in all user agents. That, however, is a well-known logical fallacy.
Which is why the code that follows that conclusion deserves to be called
error-prone.


PointedEars
.



Relevant Pages

  • Re: Dynamic select lists using optgroups again - without frameworks
    ... function at the bottom of the last script element, ... in the last script element. ... document.body or whatever) or DOM ready and it has the pleasant side ... Using onload is also based on the "mere assumption" that the UA ...
    (comp.lang.javascript)
  • Re: DOMContentReady and focus() in Opera
    ... Have the onload listener check to see if the DOM ready ... using a script which did its setup in an onload handler. ...
    (comp.lang.javascript)
  • Re: DOMContentReady and focus() in Opera
    ... and onload. ...  Have the onload listener check to see if the DOM ready ... script has run, if not, set the focus. ...
    (comp.lang.javascript)
  • Re: "onDocumentComplete" and reading the DOM of a loaded page
    ... > actually take advantage of that to change the onload script... ... since the dom might change in the onload... ... Post yourself a user-defined window message. ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Re: Causing File Download on Page Load
    ... Script code in the document head or body is executed while the document is ... So script in the onload handler executes after the document is finished loading? ... and not using a wrapper. ...
    (comp.lang.javascript)