document.execCommand(”BackgroundImageCache”, false, true)

不少时候咱们要给一些按钮或是img设置背景,而为了达到数据与表现样式分离的效果,一般背景样式都是在CSS里设定的,可是这个行为在IE会有一 个Bug,那就是由于 IE默认状况下不缓存背景图片,因此当鼠标在有CSS背景的按钮或是图片上移动时,图片会闪烁甚至鼠标会出现忙的状态,而在FireFox下没有这个问 题,为了解决这个问题,有两种解决办法,其一是在CSS中加入以下样式:html

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

但这个可能会使整个页面的加载变得很慢,因此推荐使用JS来修正这个Bug,在页面中的任意位置加入以下代码,便可达到理想中的效果:缓存

(function(){
var browser=new Object();
browser.name=navigator.appName;
if(browser.name.indexOf("Microsoft")!=-1){
browser.version=navigator.appVersion.indexOf("MISE");
browser.version=parseInt(navigator.appVersion.substring(browser.version+4));
if(browser.version<=6){
document.execCommand("BackgroundImageCache",false,true);
}
}
})(window.navigator);app

相关文章
相关标签/搜索