IE6下CSS图片缓存问题解决方法_javascript技巧
程序员文章站
2022-04-28 20:15:58
...
用一句代码即可搞定:
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;
}
复制代码 代码如下:
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;
}
推荐阅读
-
火狐下input焦点无法重复获取问题的解决方法_javascript技巧
-
IE6,IE7下js动态加载图片不显示错误_javascript技巧
-
IE 下Enter提交表单存在重复提交问题的解决方法_javascript技巧
-
ie6下png图片背景不透明的解决办法使用js实现_javascript技巧
-
IE6下javasc#ipt:void(0) 无效的解决方法_javascript技巧
-
加载远程图片时,经常因为缓存而得不到更新的解决方法(分享)_javascript技巧
-
加载远程图片时,经常因为缓存而得不到更新的解决方法(分享)_javascript技巧
-
js、css、img等浏览器缓存问题的2种解决方案_javascript技巧
-
IE6下JS动态设置图片src地址问题_javascript技巧
-
ie6下png图片背景不透明的解决办法使用js实现_javascript技巧