• <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>

            逛奔的蝸牛

            我不聰明,但我會(huì)很努力

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

            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 逛奔的蝸牛 閱讀(2059) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 其他編程
            久久久WWW成人免费精品| 69久久夜色精品国产69| 久久人人爽人人爽人人片AV东京热| 久久人人爽人爽人人爽av| 狠狠色伊人久久精品综合网| 国产成人精品三上悠亚久久| 久久国产成人午夜aⅴ影院| 伊人久久大香线蕉无码麻豆| 国産精品久久久久久久| 精品久久久久久久久免费影院| 久久er国产精品免费观看8| 久久久精品国产免大香伊 | 国产精品伊人久久伊人电影| 久久综合香蕉国产蜜臀AV| 97久久国产露脸精品国产| 色偷偷888欧美精品久久久| 国产一级做a爰片久久毛片| 国产精品久久免费| 久久亚洲AV成人无码软件| 99久久国产主播综合精品| 久久高清一级毛片| 91精品国产色综合久久| 波多野结衣AV无码久久一区| 久久涩综合| 久久播电影网| 国产69精品久久久久99| www.久久精品| 久久96国产精品久久久| 久久99国内精品自在现线| 免费观看久久精彩视频| 精品久久久久久亚洲精品 | 国内精品久久久久久久coent| 老色鬼久久亚洲AV综合| 亚洲AV无码久久精品成人 | 99精品久久精品一区二区| 亚洲AV乱码久久精品蜜桃| 亚洲精品乱码久久久久久久久久久久 | 亚洲伊人久久综合中文成人网| 久久精品?ⅴ无码中文字幕| 久久不见久久见免费影院www日本| 国产亚洲精午夜久久久久久|