IE Image Properties

claudermilkclaudermilk Registered Users Posts: 2,756 Major grins
Hopefully one of the Javascript wizards her ecan help. I have a small hack for my bio page nearly working. FF runs perfectly, but of course IE won't. THe lines in question are:
document.getElementById("slidek").style.width = document.slidek.width + "px";
document.getElementById("slidek").style.height = document.slidek.height + "px";
document.getElementById("container").style.width = document.slidek.width + 45 + "px";
document.getElementById("container").style.height = document.slidek.height + 45 + "px";
The part that's stopping the show is getting at the image height and width. I've tried about every combination I can find & at best this code works in FF, but knocks the image down to a couple-pixel-square spot on the page. So, anyone know the magic combination that IE will accept?

Comments

  • claudermilkclaudermilk Registered Users Posts: 2,756 Major grins
    edited May 12, 2006
    OK, after much (much, much, MUCH) Googling I found a solution. Hope this helps someone else in the future.

    Those four lines bloated out to this :
        //stupid IE hack >:(
        if (navigator.appName=="Microsoft Internet Explorer"){
            var tmpImg = document.createElement("IMG");
            tmpImg.src = document.getElementById("slidek").src;
            document.getElementById("slidek").style.width = tmpImg.width + "px";
            document.getElementById("slidek").style.height = tmpImg.height + "px";
            document.getElementById("container").style.width = tmpImg.width + 45 + "px";
            document.getElementById("container").style.height = tmpImg.height + 45 + "px";
        } else {
            document.getElementById("slidek").style.width = document.images["slidek"].width + "px";
            document.getElementById("slidek").style.height = document.images["slidek"].height + "px";
            document.getElementById("container").style.width = document.images["slidek"].width + 45 + "px";
            document.getElementById("container").style.height = document.images["slidek"].height + 45 + "px";
        }
    
    But it does what I want 98% of the time. Every now & then IE throws 0 for the dimensions just to be petulant.

    I hate IE. :bash
Sign In or Register to comment.