<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>IE 6PNG </title>
<style type="text/css">
img, div { behavior: url(iepngfix.htc) }
body
{
background-color:#800;
}
</style>
</head>
<body>
<img name="testImg" src="light.png" />
<div id="d" style="padding:50px;font-size:30px;color:#c90;background: url(light.png)">
<p>修正png显示</p>
</div>
</div>
</body>
</html>
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
![InBlock.gif](http://xcf007.blog.51cto.com/images/editer/InBlock.gif?x-oss-process=image/resize,w_1400/format,webp)
iepngfix.htc:
<
public:component>
< public:attach event= "onpropertychange" onevent= "doFix()" />
<script type= "text/javascript">
// IE5.5+ PNG Alpha Fix v1.0RC4
// (c) 2004-2005 Angus Turnbull [url]http://www.twinhelix.com[/url]
// This is licensed under the CC-GNU LGPL, version 2.1 or later.
// For details, see: [url]http://creativecommons.org/licenses/LGPL/2.1/[/url]
// This must be a path to a blank image. That's all the configuration you need.
if ( typeof blankImg == 'undefined') var blankImg = 'blank.gif';
var f = 'DXImageTransform.Microsoft.AlphaImageLoader';
function filt(s, m)
{
if (filters[f])
{
filters[f].enabled = s ? true : false;
if (s) with (filters[f]) { src = s; sizingMethod = m }
}
else if (s) style.filter = 'progid:'+f+'(src= "'+s+'",sizingMethod= "'+m+'")';
}
function doFix()
{
// Assume IE7 is OK.
if (!/MSIE (5\.5|6\.)/.test(navigator.userAgent) ||
(event && !/(background|src)/.test(event.propertyName))) return;
var bgImg = currentStyle.backgroundImage || style.backgroundImage;
if (tagName == 'IMG')
{
if ((/\.png$/i).test(src))
{
if (currentStyle.width == 'auto' && currentStyle.height == 'auto')
style.width = offsetWidth + 'px';
filt(src, 'scale');
src = blankImg;
}
else if (src.indexOf(blankImg) < 0) filt();
}
else if (bgImg && bgImg != 'none')
{
if (bgImg.match(/^url[( "']+(.*\.png)[)"']+$/i))
{
var s = RegExp.$1;
if (currentStyle.width == 'auto' && currentStyle.height == 'auto')
style.width = offsetWidth + 'px';
style.backgroundImage = 'none';
filt(s, 'crop');
// IE link fix.
for ( var n = 0; n < childNodes.length; n++)
if (childNodes[n].style) childNodes[n].style.position = 'relative';
}
else filt();
}
}
doFix();
</script>
</ public:component>
< public:attach event= "onpropertychange" onevent= "doFix()" />
<script type= "text/javascript">
// IE5.5+ PNG Alpha Fix v1.0RC4
// (c) 2004-2005 Angus Turnbull [url]http://www.twinhelix.com[/url]
// This is licensed under the CC-GNU LGPL, version 2.1 or later.
// For details, see: [url]http://creativecommons.org/licenses/LGPL/2.1/[/url]
// This must be a path to a blank image. That's all the configuration you need.
if ( typeof blankImg == 'undefined') var blankImg = 'blank.gif';
var f = 'DXImageTransform.Microsoft.AlphaImageLoader';
function filt(s, m)
{
if (filters[f])
{
filters[f].enabled = s ? true : false;
if (s) with (filters[f]) { src = s; sizingMethod = m }
}
else if (s) style.filter = 'progid:'+f+'(src= "'+s+'",sizingMethod= "'+m+'")';
}
function doFix()
{
// Assume IE7 is OK.
if (!/MSIE (5\.5|6\.)/.test(navigator.userAgent) ||
(event && !/(background|src)/.test(event.propertyName))) return;
var bgImg = currentStyle.backgroundImage || style.backgroundImage;
if (tagName == 'IMG')
{
if ((/\.png$/i).test(src))
{
if (currentStyle.width == 'auto' && currentStyle.height == 'auto')
style.width = offsetWidth + 'px';
filt(src, 'scale');
src = blankImg;
}
else if (src.indexOf(blankImg) < 0) filt();
}
else if (bgImg && bgImg != 'none')
{
if (bgImg.match(/^url[( "']+(.*\.png)[)"']+$/i))
{
var s = RegExp.$1;
if (currentStyle.width == 'auto' && currentStyle.height == 'auto')
style.width = offsetWidth + 'px';
style.backgroundImage = 'none';
filt(s, 'crop');
// IE link fix.
for ( var n = 0; n < childNodes.length; n++)
if (childNodes[n].style) childNodes[n].style.position = 'relative';
}
else filt();
}
}
doFix();
</script>
</ public:component>
截图
![](http://xcf007.blog.51cto.com/attachment/200810/200810251224926270593.gif?x-oss-process=image/resize,w_1400/format,webp)
本文转自 xcf007 51CTO博客,原文链接:http://blog.51cto.com/xcf007/107988,如需转载请自行联系原作者