Quantcast
Channel: Sunshow Life » ie
Viewing all articles
Browse latest Browse all 20

IE6下CSS背景图片的Bug

$
0
0

最近碰到的问题,比如有一div,设置了背景图,然后只要在js中对此div的css做出任何更改就会重新请求背景图片,表现为页面闪烁
此问题仅在IE6下出现(更低版本未测试),原因是IE6在默认情况下不缓存背景图片

解决办法一,通过css:

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

缺点:可能会使整个页面的加载速度变慢

解决办法二,使用javascript:

<script type="text/javascript">
document.execCommand('BackgroundImageCache', false, true);
<
/script>

缺点:如果在firefox等浏览器下执行会出错。
所以需要判断是否为IE浏览器,使用jQuery提供的判断方法如下:

<script type="text/javascript">
if ($.browser.msie) {
    
document.execCommand('BackgroundImageCache', false, true);
}
<
/script>
标签:, , , , , ,

Relatd Posts:

Viewing all articles
Browse latest Browse all 20

Latest Images

Trending Articles





Latest Images