document.execCommand("BackgroundImageCache",false,true)解决ie6下的背景图片缓存问题

E6下的背景图片每次使用都会重新发送请求(not 本地),连一个hover效果时候同样的背景图片仅仅位置不同而已,ie6都会再次发送请求,这个令人崩溃的事情需要解决掉:
对于ie来说,filter:expression 很强大,能够实现的功能超级多,但是更对于视效率如生命的程序员来说,它的效率不敢令人恭维,所以有人会用css方法实现ie6下背景图片缓存,但是这种人也就是崇拜微软的强大而已,无它,

html {filter:expression(document.execCommand("BackgroundImageCache", false, true));}

当然大多数人都会选择js方法实现:

(function(){
    try{
        var userAgent = navigator.userAgent.toLowerCase();
        var env = null;
        var ver = 0;
        env = userAgent.match(/msie ([\d.]+)/);ver = env ? parseInt(env[1], 10) : 0;
        if(ver == 6){
            try{ 
                document.execCommand("BackgroundImageCache", false, true);
            }catch(e){}
        }
    }catch(e){}
})();

附:jQuery判断浏览器总结

var isFF = (navigator.userAgent.toLowerCase().indexOf("firefox") != -1);
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isIE6 = (navigator.appVersion.indexOf("MSIE 6.0") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
var isChrome = (navigator.userAgent.indexOf("Chrome") != -1) ? true : false;
var isSafari = (navigator.userAgent.indexOf("Safari") != -1) ? true : false;
if (isIE6) {
    try { //IE6下缓存背景图片
         document.execCommand("BackgroundImageCache", false, true);
        } catch (e) {}
           }

 

posted @ 2014-04-08 13:28  leejersey  阅读(1214)  评论(0编辑  收藏  举报