IE6下CSS圖片緩衝問題解決方案

來源:互聯網
上載者:User

用一句代碼即可搞定: 複製代碼 代碼如下:document.execCommand("BackgroundImageCache", false, true);

當然為了其它瀏覽器上能正常通過,需要做下判斷後調用,才更安全:

複製代碼 代碼如下:if(Browser.isIE6){
try{
document.execCommand("BackgroundImageCache", false, true);
}
catch(e1){}
}

平台檢測代碼可以這樣寫,摘自Ext源碼:

複製代碼 代碼如下:var Browser = {};
try{
(function(){
var idSeed = 0,
ua = navigator.userAgent.toLowerCase(),
check = function(r){
return r.test(ua);
},
DOC = document,
isStrict = DOC.compatMode == "CSS1Compat",
isOpera = check(/opera/),
isChrome = check(/\bchrome\b/),
isWebKit = check(/webkit/),
isSafari = !isChrome && check(/safari/),
isSafari2 = isSafari && check(/applewebkit\/4/), // unique to Safari 2
isSafari3 = isSafari && check(/version\/3/),
isSafari4 = isSafari && check(/version\/4/),
isIE = !isOpera && check(/msie/),
isIE7 = isIE && check(/msie 7/),
isIE8 = isIE && check(/msie 8/),
isIE6 = isIE && !isIE7 && !isIE8,
isGecko = !isWebKit && check(/gecko/),
isGecko2 = isGecko && check(/rv:1\.8/),
isGecko3 = isGecko && check(/rv:1\.9/),
isBorderBox = isIE && !isStrict,
isWindows = check(/windows|win32/),
isMac = check(/macintosh|mac os x/),
isAir = check(/adobeair/),
isLinux = check(/linux/),
isIpad = check(/ipad/),
isSecure = /^https/i.test(window.location.protocol);
extend(Browser,{
isOpera:isOpera,
isIE:isIE,
isIE6:isIE6,
isFirefox:isGecko,
isSafari:isSafari,
isChrome:isChrome,
isIpad:isIpad
});
})();
}catch(e){}

//上面extend方法也很easy

複製代碼 代碼如下:function extend(obj1,obj2){
for(var o in obj2){
obj1[o] = obj2[o];
}
return obj1;
}
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.