• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            逛奔的蝸牛

            我不聰明,但我會很努力

               ::  :: 新隨筆 ::  ::  :: 管理 ::

            Are you attaching an onload function to an image but finding it doesn't always get called?

            The problem is almost always this: you need to set the onload before you set the src. The reason is obvious when you think about it: if the image is in the cache, the image will be loaded immediately after setting the src, even before the onload is set.

            Adding fuel to the fire, Firefox and Safari will let you set an onload immediately after (it seems they don't call the onload until the block of JavaScript finishes). This doesn't happen in Internet Explorer or Opera.

            Long story short:

            // evil:
            var image = new Image();
            image.src = 'image.jpg';
            image.onload = function() {
                // sometimes called
                alert('image loaded');
            };
            
            // good:
            var image = new Image();
            image.onload = function() {
                // always called
                alert('image loaded');
            };
            image.src = 'image.jpg';
            

            No matter how many times I come across this bug and find the solution, I end up making the same mistake a few weeks later. I'm hoping that blogging about it will get this stuck in my long-term memory.


            From: http://www.thefutureoftheweb.com/blog/image-onload-isnt-being-called

            posted on 2010-09-06 21:55 逛奔的蝸牛 閱讀(2064) 評論(0)  編輯 收藏 引用 所屬分類: 其他編程
            日本精品久久久久中文字幕 | 狠狠色伊人久久精品综合网| 久久香蕉国产线看观看99| 国产福利电影一区二区三区久久老子无码午夜伦不 | 久久福利青草精品资源站| 欧美国产精品久久高清| 精品国产一区二区三区久久久狼| 久久久九九有精品国产| 一本久久a久久精品vr综合| 国产一区二区精品久久凹凸| 久久久久亚洲AV无码专区首JN| 丁香五月综合久久激情| 狠狠色婷婷久久综合频道日韩 | 国产99久久九九精品无码| 久久乐国产综合亚洲精品| 国产激情久久久久影院老熟女免费 | 午夜精品久久久久久| 久久久综合九色合综国产| 超级碰碰碰碰97久久久久| 国内精品久久久久久麻豆| 99国产欧美精品久久久蜜芽| 亚洲va国产va天堂va久久| 亚洲?V乱码久久精品蜜桃| 久久久久九九精品影院| 成人亚洲欧美久久久久| 精品国产婷婷久久久| 久久精品国产69国产精品亚洲| 久久天天躁狠狠躁夜夜avapp| 久久人人添人人爽添人人片牛牛| 亚洲七七久久精品中文国产 | 午夜精品久久久久久影视777 | 亚洲AV无码久久| 久久久91人妻无码精品蜜桃HD| 精品永久久福利一区二区| 久久亚洲春色中文字幕久久久| 人妻精品久久久久中文字幕一冢本| 中文字幕无码久久久| 99久久夜色精品国产网站| 日韩AV无码久久一区二区 | 久久久亚洲裙底偷窥综合| 伊人久久大香线蕉亚洲|