[thelist] PNG support in IE, using WebFX script
Chris W. Parker
cparker at swatgear.com
Mon Dec 23 12:27:01 CST 2002
hi.
recently i discovered a script that allows IE to support PNG's as they
were intended to be used. the script works by detecting what browser the
client is using and adding an IE filter if the browser is found to be
IE/Win32. all other browsers are left alone.
the problem is that IE complains about one line in the .htc file i use.
here is the entire script... (watch wrap)
<public:component>
<public:attach event="onpropertychange" onevent="propertyChanged()" />
<script>
var supported = /MSIE (5\.5)|[6789]/.test(navigator.userAgent) &&
navigator.platform == "Win32";
var realSrc;
var blankSrc = "images/spacer.gif";
if (supported) fixImage();
function propertyChanged() {
if (!supported) return;
var pName = event.propertyName;
if (pName != "src") return;
// if not set to blank
if ( ! new RegExp(blankSrc).test(src))
fixImage();
};
function fixImage() {
// get src
var src = element.src;
// check for real change
if (src == realSrc) {
element.src = blankSrc;
return;
}
if ( ! new RegExp(blankSrc).test(src)) {
// backup old src
realSrc = src;
}
// test for png
if ( /\.png$/.test( realSrc.toLowerCase() ) ) {
// set blank image
element.src = blankSrc;
// set filter
element.runtimeStyle.filter =
"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +
src + "',sizingMethod='scale')";
}
else {
// remove filter
element.runtimeStyle.filter = "";
}
}
</script>
</public:component>
the line in question is #37 which reads...
if ( /\.png$/.test( realSrc.toLowerCase() ) ) {
and the error IE is reporting is "'realSrc' is null or not an object".
i want that to go away and i'm not sure what the problem is. the funny
part (funny strange, not funny haha) is that it works fine (no error
reported) on a basic test page i use but not on the "production" page.
although one page has a lot more markup the script is executed in the
same way.
any ideas?
chris.
p.s. no links were provided because both pages are on a private server.
i can move them somewhere public if necessary.
More information about the thelist
mailing list