Need a bit of help replacing ID to Name tag

P

Paul

HI! I have a script below that fixes a lack of support in IE for
transparency png images when used as part of a rollover effect. it works
well but I had add a ID tag in the img line that Dreamweaver makes by
default.

So. to make this script compatible with Dreamweaver 7 or 8 we have to make
this script look for a name="imagename" tag and not id="imagename" as its
doing now in the script below.

Can someone tell me which part of the script below to change exactly in
order for it look for a name tag?

Thanks in advance :)

Paul

-------------Script-------------

<!--[if gte IE 5.5000]>
<script type="text/javascript">
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or
higher.
{
for(var i=0; i<document.images.length; i++)
{
var img = document.images
var imgName = img.src.toUpperCase()
if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
{
var imgID = (img.id) ? "id='" + img.id + "' " : ""
var imgClass = (img.className) ? "class='" + img.className + "' " : ""
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" +
img.alt + "' "
var imgStyle = "display:inline-block;" + img.style.cssText
var imgAttribs = img.attributes;
for (var j=0; j<imgAttribs.length; j++)
{
var imgAttrib = imgAttribs[j];
if (imgAttrib.nodeName == "align")
{
if (imgAttrib.nodeValue == "left") imgStyle = "float:left;" + imgStyle
if (imgAttrib.nodeValue == "right") imgStyle = "float:right;" +
imgStyle
break
}
}
var strNewHTML = "<span " + imgID + imgClass + imgTitle
strNewHTML += " style=\"" + "width:" + img.width + "px; height:" +
img.height + "px;" + imgStyle + ";"
strNewHTML +=
"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
strNewHTML += "(src='" + img.src + "', sizingMethod='scale');\""
strNewHTML += " onmouseover=\"PNGswap('" + img.id + "');\"
onmouseout=\"PNGswap('" + img.id +"');\""
strNewHTML += "></span>"
img.outerHTML = strNewHTML
i = i-1
}
}
}
window.attachEvent("onload", correctPNG);

function PNGswap(myID)
{
var strOver = "_on"
var strOff = "_off"
var oSpan = document.getElementById(myID)
var currentAlphaImg = oSpan.filters(0).src
if (currentAlphaImg.indexOf(strOver) != -1)
oSpan.filters(0).src = currentAlphaImg.replace(strOver,strOff)
else
oSpan.filters(0).src = currentAlphaImg.replace(strOff,strOver)
}

</script>
<![endif]-->

--------End of script-----------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top