Welcome to Dream.In.Code
Getting Help is Easy!

Join 107,709 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,108 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



.png IE transparency fix breaks image map?

 
Reply to this topicStart new topic

.png IE transparency fix breaks image map?, Need help combining Javascript functions

jw2k_fr
post 4 Apr, 2006 - 12:43 PM
Post #1


New D.I.C Head

*
Joined: 4 Apr, 2006
Posts: 2


My Contributions


Hi

I have been trying to get a fairly simple couple of webpages finished, but have fallen at the final hurdle. I worked my way through the whole .png transparency problem in IE and have a version of that code fix pasted into the second page I am using and it works fine. However, when I try to paste it into the first page (where I already have a javascript function) it breaks the functionality of my existing page (but it does fix the transparency problem).

Here is a sample of the problematic page:

CODE

<html>
<head>

<script type="text/javascript">
var bookopen = 0

function clickbook(iField)
{
 if (bookopen == 0)
 {
     document.image"[addressbook"].src="inside_address_book.png";
     bookopen = 1
 }
 else
 {
   switch (iField)
   {
     case 1  : window.location="guadalupe/index.htm";
           break;
     case 2  : window.location="pablo.htm";
           break;
     case 3  : window.location="http://www.wedding.net"
           break;
     default : document.images["addressbook"].src="book_cover.png";
           bookopen = 0;
   }
 }
}

</script>


<!--[if lt IE 7]>
<script language="JavaScript">
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
  var arVersion = navigator.appVersion.split("MSIE")
  var version = parseFloat(arVersion[1])
  if ((version >= 5.5) && (document.body.filters))
  {
     for(var i=0; i<document.images.length; i++)
     {
        var img = document.images[i]
        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
           if (img.align == "left") imgStyle = "float:left;" + imgStyle
           if (img.align == "right") imgStyle = "float:right;" + imgStyle
           if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
           var strNewHTML = "<span " + imgID + imgClass + imgTitle
           + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
           + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
           + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
           img.outerHTML = strNewHTML
           i = i-1
        }
     }
  }    
}
window.attachEvent("onload", correctPNG);
</script>
<![endif]-->
    
</head>


<body link="990000" vlink="990000" alink="990000"bgcolor="FFF4D9">  
     

<table cellpadding="0" cellspacing="0" border="0" align="center" width="100%" height="100%">
 <tr>
   <td align="center" height="100%"><img name="addressbook" src="address_book_cover.png" WIDTH=520 HEIGHT=325 border="0" usemap="#links"></td>
 </tr>
</table>

<map name="links">
 <area alt="The adventures of Botella Guadalupe" coords="270,1,520,120" href="javascript:clickbook(1)">
 <area alt="Pablo & Muriel" coords="270,121,520,195" href="javascript:clickbook(2)">
 <area alt="The wedding" coords="270,196,520,320" href="javascript:clickbook(3)">
 <area alt="Close the book" coords ="20,285,80,305"   href="javascript:clickbook()">
</map>

</body>
</html>




If I remove the .png transparency fix function correctPNG(), the image map works flawlessly, changing from a picture of the open cover of an address book to the inside of the address book whereupon, if you click one of the image map fields you are taken to another page; otherwise the image is changed to the closed cover of the address book:

CODE

<html>
<head>
    <title>&nbsp;&nbsp;&nbsp;Marianne O'Sheeran</title>
    
<script type="text/javascript">
var bookopen = 0

function clickbook(iField)
{
 if (bookopen == 0)
 {
     document.images["addressbook"].src="inside_address_book.png";
           bookopen = 1
 }
 else
 {
   switch (iField)
   {
     case 1  : window.location="guadalupe/index.htm";
           break;
     case 2  : window.location="pablo.htm";
           break;
     case 3  : window.location="http://www.wedding.net"
           break;
     default : document.images["addressbook"].src="book_cover.png";
           bookopen = 0;
   }
 }
}

</script>

</head>

<body link="990000" vlink="990000" alink="990000"bgcolor="FFF4D9">  
     

<table cellpadding="0" cellspacing="0" border="0" align="center" width="100%" height="100%">
 <tr>
   <td align="center" height="100%"><img name="addressbook" src="marianne_address_book_cover.png" WIDTH=520 HEIGHT=325 border="0" usemap="#links"></td>
 </tr>
</table>

<map name="links">
 <area alt="The adventures of Botella Guadalupe" coords="270,1,520,120" href="javascript:clickbook(1)">
 <area alt="Pablo & Muriel" coords="270,121,520,195" href="javascript:clickbook(2)">
 <area alt="The wedding" coords="270,196,520,320" href="javascript:clickbook(3)">
 <area alt="Close the book" coords ="20,285,80,305"   href="javascript:clickbook()">
</map>

</body>
</html>



Can anyone tell me what is causing the above problem and how I can fix it?

Many thanks in advance

James
User is offlineProfile CardPM

Go to the top of the page


snoj
post 4 Apr, 2006 - 02:34 PM
Post #2


$Null

Group Icon
Joined: 31 Mar, 2003
Posts: 3,304



Thanked 4 times

Dream Kudos: 700
My Contributions


Is there some reason you're using javascript to apply the IE only CSS "filter" property? Why not just apply it to all images with CSS since only IE can use "filter"?

Though this may NOT solve your problem, it will really cut down on the needed page code.
User is offlineProfile CardPM

Go to the top of the page

jw2k_fr
post 4 Apr, 2006 - 02:45 PM
Post #3


New D.I.C Head

*
Joined: 4 Apr, 2006
Posts: 2


My Contributions


I am absolutely up for doing things the tidy way, but am not sure how I would transfer this to a CSS.

Due to the mainly graphical nature of the pages, this is the extent of my basic CSS so far:

CODE


BODY  {
    background: white url("cracked paint backdrop.jpg");
     background-repeat: repeat;
    }    

/*Margins are TOP  RIGHT  BOTTOM  LEFT   */

.titlepage_text {margin: 0px 0px 0px 0px;    padding: 0px 20px 10px 15px;
 font: 2.0em/2.0  "Monotype Corsiva", serif;
 color: #e6e6e6;   background: black;
 }

.titlepage_link {margin: 0px 0px 0px 0px;    padding: 0px 20px 10px 15px;
 font: 1.2em/2.0  "Times New Roman", serif;
 color: #e6e6e6;   background: black;
 }


How would I move the function into the CSS?

Thanks

James
User is offlineProfile CardPM

Go to the top of the page

Arbitrator
post 4 Apr, 2006 - 11:38 PM
Post #4


D.I.C Regular

Group Icon
Joined: 26 Jan, 2005
Posts: 492


My Contributions


Like any filter, you can place it directly into the CSS. However, that is not the purpose of the JavaScript.

First, when MSIE filters the image and makes it transparent, it still leaves the unfiltered image under it so that you in essence see the same unfiltered image you saw before. You can get around this by changing the original src to a transparent GIF so that the unfiltered image won't interfere with the newly filtered image. However, you run into the problem of the image not working in anything other than Internet Explorer since the transparent GIF will be displayed.

You could use a conditional comment to deliver a new image URL to Internet Explorer, though I'm unaware of a way to change the image source URL through CSS alone. Without such a method that means you're going to have to use something like JavaScript or PHP as an intermediary; I'm relatively unfamiliar with either so I can't tell you precisely what the script does.

Solution I used: http://homepage.ntlworld.com/bobosola/pnghowto.htm
Explanation of the problem: http://koivi.com/ie-png-transparency/

After briefly looking at your problem it sounds like you're trying to do an image swap; unless both images are already loaded I'm not sure if you can filter them since the filter seems to work onLoad; whether this is on the load of the page itself or each image, I can't say.

This post has been edited by Arbitrator: 4 Apr, 2006 - 11:39 PM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/30/08 03:09AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month