Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #19910

Re: Q: How to reset onload event handler that was set to null?

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> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <usenet@PointedEars.de>
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+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
Subject Re: Q: How to reset onload event handler that was set to null?
Newsgroups comp.lang.javascript
References <knja7u$3mm$1@news.albasani.net> <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<CGPPU8j_I0DN6_4IUK<Cl32<Q4Fo<]lROoRQ8kF<OcfhCO[IHeiH@`A^PVDZm8W4\YJN\b@mF9jNikdU7a5\<`>]gf^WNg]>UkYk5W
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:19910

Show key headers only | View raw


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.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Q: How to reset onload event handler that was set to null? Tuxedo <tuxedo@mailinator.com> - 2013-05-22 22:36 +0200
  Re: Q: How to reset onload event handler that was set to null? Tuxedo <tuxedo@mailinator.com> - 2013-05-22 23:32 +0200
    Re: Q: How to reset onload event handler that was set to null? Tuxedo <tuxedo@mailinator.com> - 2013-05-23 00:12 +0200
  Re: Q: How to reset onload event handler that was set to null? JJ <duh@nah.meh> - 2013-05-23 08:47 +0700
  Re: Q: How to reset onload event handler that was set to null? Christian Winter <thepoet_nospam@arcor.de> - 2013-05-23 07:48 +0200
    Re: Q: How to reset onload event handler that was set to null? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-23 10:19 +0200
      Re: Q: How to reset onload event handler that was set to null? Christian Winter <thepoet_nospam@arcor.de> - 2013-05-23 18:06 +0200
        Re: Q: How to reset onload event handler that was set to null? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-23 18:31 +0200
  Re: Q: How to reset onload event handler that was set to null? sake mera <sakemera@gmail.com> - 2013-05-23 14:02 -0700

csiph-web