• <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)  編輯 收藏 引用 所屬分類: 其他編程
            一本色综合久久| 伊人丁香狠狠色综合久久| 性欧美大战久久久久久久| 无码乱码观看精品久久| 国产激情久久久久久熟女老人| 久久免费的精品国产V∧| 99久久99久久精品国产片| 久久久久噜噜噜亚洲熟女综合 | 久久综合伊人77777| 久久99热这里只有精品国产| 99久久综合狠狠综合久久止| 模特私拍国产精品久久| 亚洲乱亚洲乱淫久久| 亚洲欧洲日产国码无码久久99| 久久精品国产亚洲麻豆| 99精品久久精品一区二区| 精品国产婷婷久久久| 99久久精品毛片免费播放| 伊人伊成久久人综合网777| 国产综合精品久久亚洲| 国产精品久久久久久影院| 精品久久人人爽天天玩人人妻| 久久99国产精品久久久 | 色综合久久中文综合网| 亚洲狠狠婷婷综合久久久久| 综合久久一区二区三区 | 2021最新久久久视精品爱| 久久国产视屏| 久久99精品久久久久久齐齐| 91久久精品电影| 久久综合久久综合久久综合| 国内精品久久久久久久97牛牛| 久久亚洲中文字幕精品一区| 国内精品久久国产| 久久精品日日躁夜夜躁欧美| 中文精品久久久久人妻不卡| 久久精品日日躁夜夜躁欧美| 久久久久亚洲精品日久生情 | 久久国产亚洲高清观看| 国产V综合V亚洲欧美久久| www.久久精品|