• <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)  編輯 收藏 引用 所屬分類: 其他編程
            亚洲精品成人久久久| 久久国产成人| 国产成人精品久久免费动漫| 久久精品九九亚洲精品| 精品久久久久久久中文字幕| 久久久SS麻豆欧美国产日韩| 99久久精品午夜一区二区| 精品久久国产一区二区三区香蕉 | 国产精品美女久久久网AV| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 中文字幕日本人妻久久久免费 | 亚洲欧美成人久久综合中文网 | 国产精品9999久久久久| 婷婷久久综合| 99久久国语露脸精品国产| 久久久久久国产精品无码下载| 久久天堂电影网| 老男人久久青草av高清| 99久久成人18免费网站| 日韩精品无码久久久久久| 一本综合久久国产二区| 久久e热在这里只有国产中文精品99 | 东京热TOKYO综合久久精品| 色狠狠久久综合网| 久久91这里精品国产2020| 青青草原综合久久大伊人精品| 人妻无码αv中文字幕久久琪琪布 人妻无码久久一区二区三区免费 人妻无码中文久久久久专区 | 久久久久久久精品妇女99| 色婷婷综合久久久久中文字幕| 国产精品久久久久乳精品爆| 夜夜亚洲天天久久| 久久se精品一区二区| 国产精品一久久香蕉国产线看| 久久久久久久97| 亚洲AV日韩精品久久久久久| 久久综合九色综合网站| 久久亚洲AV无码精品色午夜| 伊人久久大香线蕉精品不卡| 一本色综合久久| 日本久久久久亚洲中字幕| 久久婷婷成人综合色综合|