[TYPO3-dev] JSeventFunCalls onload executed twice
Peter Klein
peter at umloud.dk
Fri Dec 29 14:20:05 CET 2006
Hi Christoph.
The way TYPO3 does onload events is ancient, and is not very compatible with
other scripts that access the onload property.
In my Textarea Widget Extension
(http://typo3.org/extensions/repository/view/pmktextarea/0.1.2/) I create
the onload handler directly from JS, like this:
-- cut --
function addEvent(obj, evType, fn, useCapture) {
if (obj.addEventListener) {
obj.addEventListener(evType, fn, useCapture);
return true;
} else if (obj.attachEvent) {
var r = obj.attachEvent("on"+evType, fn);
return r;
} else {
alert('Handler could not be attached');
}
}
function removeEvent(obj, evType, fn, useCapture){
if (obj.removeEventListener){
obj.removeEventListener(evType, fn, useCapture);
return true;
} else if (obj.detachEvent){
var r = obj.detachEvent('on' + evType, fn);
return r;
} else {
alert('Handler could not be removed');
}
}
addEvent(window, 'load', function() { textarea_init(); }, false);
-- cut --
This adds the function "textarea_init" to the onload handler. You can then
add more functions (or remeove them) as you see fit.
And it works with other scripts that access the onload property directly
(like TYPO3)
--
Peter Klein / Umloud Untd.
"Christoph Koehler" <christoph.koehler at gmail.com> wrote in message
news:mailman.1.1167304187.11808.typo3-dev at lists.netfielders.de...
> Hey there,
>
> I noticed that the JSevent onload adds a onload to the body tag as well as
> a document.onload to the JS, which I think results in everything that is
> called to be loaded twice. Might not be too bad for most things, but
> Google Maps is loaded that way and doing that is not a cheap process.
> Is there any reason for that?
>
> Christoph
More information about the TYPO3-dev
mailing list