• <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 逛奔的蝸牛 閱讀(2069) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 其他編程
            国产精品久久久久…| 少妇高潮惨叫久久久久久| 狠狠综合久久AV一区二区三区| 97精品伊人久久大香线蕉| 一本一本久久aa综合精品| 亚洲精品乱码久久久久久中文字幕| 国产激情久久久久久熟女老人| AV色综合久久天堂AV色综合在| 欧美国产精品久久高清| 蜜臀av性久久久久蜜臀aⅴ| 久久久这里有精品| 国内精品久久久久久久coent| 99久久99这里只有免费费精品| 久久久久一级精品亚洲国产成人综合AV区 | 色综合久久久久综合99| 国产精品永久久久久久久久久 | 久久99精品久久只有精品| 久久国产成人午夜AV影院| 人人狠狠综合久久88成人| 午夜精品久久影院蜜桃| 精品久久久久久中文字幕| 777米奇久久最新地址| 一本色道久久88—综合亚洲精品| 国产激情久久久久影院老熟女免费 | 国产欧美久久久精品影院| 丰满少妇人妻久久久久久4| 久久精品中文无码资源站| 久久久久久亚洲精品成人| 久久受www免费人成_看片中文| 99久久免费只有精品国产| 久久精品夜色噜噜亚洲A∨| 久久精品人人做人人妻人人玩| 狠狠色丁香久久婷婷综合蜜芽五月| AAA级久久久精品无码区| 99久久国产综合精品网成人影院 | 国产巨作麻豆欧美亚洲综合久久| 久久国产热精品波多野结衣AV| 日产精品久久久久久久性色| 久久久久久国产精品无码下载| 午夜久久久久久禁播电影| 久久无码高潮喷水|