Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.fsmpi.rwth-aachen.de!uucp.gnuu.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <68490006.87kGhmC2VG@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Thu, 23 May 2013 18:31:26 +0200 User-Agent: KNode/4.10.2 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. <519dada2$0$6636$9b4e6d93@newsspool2.arcor-online.net> <1761150.Rbm2vAZQEd@PointedEars.de> <519e3e89$0$6624$9b4e6d93@newsspool2.arcor-online.net> MIME-Version: 1.0 Lines: 71 NNTP-Posting-Date: 23 May 2013 18:31:26 CEST NNTP-Posting-Host: 85f07181.newsspool4.arcor-online.net X-Trace: DXC=B\\oX_9]gf^WNg]>UkYk5W X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:19910 Christian Winter wrote: > Am 23.05.2013 10:19, schrieb Thomas 'PointedEars' Lahn: >> Christian Winter wrote: >>> You can store the old event handler in a local variable and >>> create a closure around it which re-adds it in a temporary >>> onload handler. >>> >>> function bla() { >>> var oldhandler = document.getElementById('bla').onload; >>> document.getElementById('bla').onload = function() { >>> document.getElementById('bla').onload = oldhandler; >>> } >>> document.getElementById('bla').src = 'another.jpg'; >>> } >>> >>> See http://jibbering.com/faq/notes/closures/ for details on >>> closures in ECMAScript. >> >> You have not answered the question > > I didn't spoon-feed the absolute answer, I illustrated saving > and restoring the original handler (which I consider the main > problem). I might have been a bit misled by the example code > that changes the src attribute only once, in that case your > solutions with either a globally accessible property or an OO > approach would be preferable. In your example you save the old event-handler property value in the *local* variable, then overwrite the event-handler property value with a function in which the old event-handler property value is overwritten with the saved value. Then you change value of the “src“ property, thereby overwriting the old value with *itself*. And you do that by retrieving the DOM object reference repeatedly when you could have used a variable or simply “this”. And the OP asked about how to save the value in one function and restore it in *another*. >> and your code not only does not make any sense as-is > > Please don't start nit-picking. There is no nit to pick: your code is complete nonsense. >> it is potentially harmful. > > -v please. See below. >> The “onload” event handler property value of Image instances must be set > > to “null” after the event occurred, in order to avoid infinite ^^^^^^^^ > > triggering in Opera (which is probably what the OP wisely did; now they ^^^^^^^^^^ > > want to change the image resource and do it all over again, probably > > for a slideshow). > > I haven't stumbled over that behaviour in Opera yet, and Google is > unwilling to provide me with more insight. Do you have a link handy? Granted, the behavior is known to me for animated GIFs in Opera, but it might occur in other cases, too. IIRC it was either Martin Honnen who pointed it out in de.comp.lang.javascript or Lasse Reichstein Nielsen who pointed it out here; and no, I do not have a link. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.