• <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)  編輯 收藏 引用 所屬分類: 其他編程
            青青青青久久精品国产h久久精品五福影院1421 | 久久国产福利免费| 精品久久久久久国产三级| 久久青青草原精品国产不卡| 久久这里的只有是精品23| 久久99精品国产麻豆| 欧美精品福利视频一区二区三区久久久精品 | 蜜臀av性久久久久蜜臀aⅴ麻豆| 2022年国产精品久久久久| 久久久久久久久久免免费精品| 亚洲第一极品精品无码久久| 中文字幕亚洲综合久久| 99久久精品国产一区二区 | 国产亚洲美女精品久久久| 亚洲AV无码成人网站久久精品大| 久久精品一区二区三区不卡| 欧美日韩精品久久久免费观看| a高清免费毛片久久| 伊人色综合久久天天人手人婷| 国产成人精品综合久久久| 久久精品国产亚洲av日韩| 亚洲婷婷国产精品电影人久久| 久久99国产精品久久99果冻传媒| 亚洲综合伊人久久大杳蕉| 日韩亚洲国产综合久久久| 久久本道综合久久伊人| 久久夜色精品国产亚洲| 狠狠色丁香婷婷综合久久来| 久久精品国产亚洲精品2020| 亚洲色大成网站WWW久久九九| 色婷婷噜噜久久国产精品12p| 精品久久久久中文字| 91麻豆精品国产91久久久久久| 久久Av无码精品人妻系列| 亚洲AV无一区二区三区久久| 一本色道久久88—综合亚洲精品 | 欧美精品九九99久久在观看| 女同久久| 色狠狠久久AV五月综合| 一本一本久久A久久综合精品 | 色播久久人人爽人人爽人人片aV|