On Dec 16, 6:16 am, "Alex McAuley" <webmas...@thecarmarketplace.com>
wrote:
> Why not attach the widget code to dom:ready....
>
> Alex Mcauleyhttp://www.thevacancymarket.com
Script tags are executed in strict document order on all browsers
(unless the `defer` attribute is put on the script tag), not least
because the scripts might output to the document inline via
`document.write` -- and so order of execution is critical. (The
`defer` attribute changes that by telling the browser that the script
won't be outputting to the document and so the browser can continue
formatting and parsing without executing the script, if it wants.) But
I'm guessing you're not using `defer`, so things will occur in
document order.
Regarding running in parallel, JavaScript in browsers is single-
threaded (by design), so you can be certain your script is the only
one running on the page at the moment it's running.
You can't *reliably* use code that accesses the DOM (`$$`) inline; you
need to go looking for things once the DOM is fully-populated. That's
why Prototype supplies the dom:loaded event, although there are other
ways, including window.onload (but that waits until images are
complete), putting the call to trigger things in a script right at the
end of the document before the closing <html> tag (and even then, I'd
use a Function#defer to let the browser really finish, but I'm a bit
paranoid), etc.
But forget the DOM for a moment, I can't see any reason why `$A` would
be undefined as long as the code using it appears in a script loaded
after Prototype. But I'm not sure I follow you about Prototype getting
"redefined" -- is it being included more than once? I'm pretty sure
that doesn't work (in fact, we just had a thread here in the group
about a specific way that didn't work on IE7).
If Prototype isn't being loaded more than once, are there other third-
party scripts or libraries on the page that may be interfering with `
$A`?
HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com
As a simple test, I only included this code once in the body tag:
if (typeof(RAN_ONCE) === 'undefined') {
RAN_ONCE = true;
// minified Prototype code here
// minified my widget code here
}
It succeeds in IE but fails in FF with the "$A undefined" error. Now
I know it is not a matter of Prototype being redefined. It fails with
just running once!