• <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 逛奔的蝸牛 閱讀(2064) 評論(0)  編輯 收藏 引用 所屬分類: 其他編程
            午夜视频久久久久一区 | 亚洲av伊人久久综合密臀性色| 久久综合九色欧美综合狠狠| 欧美精品国产综合久久| 精品久久久噜噜噜久久久| 久久九九青青国产精品| 最新久久免费视频| 四虎国产精品免费久久5151 | 久久精品国产99国产精品澳门| 精品久久久久久无码国产| 国产99久久精品一区二区| 久久人人超碰精品CAOPOREN | 色噜噜狠狠先锋影音久久| 久久久精品国产亚洲成人满18免费网站| 久久人做人爽一区二区三区| 久久93精品国产91久久综合| 久久青青草原国产精品免费| 亚洲AV日韩精品久久久久久| 久久久免费观成人影院 | 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 免费精品国产日韩热久久| 亚洲精品乱码久久久久久| 国产精品欧美久久久天天影视| 久久国产AVJUST麻豆| 97久久国产亚洲精品超碰热| 亚洲天堂久久精品| 国产亚州精品女人久久久久久| 亚洲精品tv久久久久久久久久| 国内精品久久国产| 91久久香蕉国产熟女线看| 亚洲国产综合久久天堂| 久久久国产精品福利免费| 精品国产婷婷久久久| 久久人人爽人人爽人人AV东京热| 97精品久久天干天天天按摩| 久久国产高清字幕中文| 久久精品99无色码中文字幕| 97精品伊人久久久大香线蕉| 久久精品国产99久久丝袜| 久久久久久午夜成人影院| 99久久国产宗和精品1上映|