MikeFoster

msg:1493556 | 8:37 pm on Jan 24, 2005 (gmt 0) |
The xhtml file: <html> <head> <script type='text/javascript' src='behaviors.js'></script> </head> <body> <img id="Photo" src="" alt="" width="100" height="150" /> </body> </html> The file 'behaviors.js': window.onload = function() { if (document.getElementById) { var img = document.getElementById('Photo'); if (img) img.onload = InitFade; } } function InitFade() { ... }
|
Bernard Marx

msg:1493557 | 10:01 pm on Jan 24, 2005 (gmt 0) |
Mike, I think you've missed something there. When window.onload fires, the image will have already loaded. I personally can't see a way of doing this while guaranteeing that the image's onload event hasn't already fired. The only scenario where I can see a dynamic onload event listener assignment working is where the image's src is defined (or changed) after the listener assignment.
|
MikeFoster

msg:1493558 | 4:34 am on Jan 25, 2005 (gmt 0) |
You're right, I missed it :) This is clunky... but might work: <html> <head> </head> <body> <img id="Photo" src="" alt="" width="100" height="150" /> <script type='text/javascript' src='behaviors.js'></script> </body> </html> The file 'behaviors.js': if (document.getElementById) { var img = document.getElementById('Photo'); if (img) img.onload = InitFade; } function InitFade() { ... }
|
|