• <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ⅴ| 久久精品国产国产精品四凭| 久久伊人中文无码| 久久精品人人做人人爽97| 久久精品成人影院| 97精品国产91久久久久久| 久久婷婷午色综合夜啪| 久久精品国产亚洲麻豆| 亚洲日韩中文无码久久| 99久久综合国产精品二区| 久久久久人妻一区二区三区 | 久久综合久久鬼色| 久久av无码专区亚洲av桃花岛| 久久综合五月丁香久久激情| 大伊人青草狠狠久久| 无码伊人66久久大杳蕉网站谷歌| 美女久久久久久| 久久国产精品免费| 久久最新精品国产| 国内精品人妻无码久久久影院| 久久强奷乱码老熟女| 国产综合免费精品久久久| 国产成人精品久久一区二区三区| 亚洲精品无码久久久影院相关影片| 久久综合精品国产一区二区三区| 国内精品久久久久久久久| 亚洲成人精品久久| 精品久久久久久无码国产| 国产999精品久久久久久| 精品国产婷婷久久久| 久久福利片| 亚洲国产精品无码久久九九| 久久久久亚洲av成人无码电影| 久久精品夜色噜噜亚洲A∨| 精品久久久久久无码免费| 色8激情欧美成人久久综合电| 亚洲精品视频久久久| av色综合久久天堂av色综合在| 精品久久久久久中文字幕大豆网| 亚洲国产欧美国产综合久久|