www.webdeveloper.com
Results 1 to 3 of 3

Thread: Not working on IE

  1. #1
    Join Date
    Sep 2013
    Posts
    2

    Lightbulb Not working on IE

    Hi, guys!

    Though an experienced programmer, I'm a Javasript beginner!

    The code below is not complete. I'm just trying to get the values, and afterward I'll use them to resize my image. Please help me find out why this code tests ok in Chrome but shows "undefined" values in IE.

    <!doctype html>

    <body style="color:white;" onload="Resize()">
    <script>
    function Resize()
    {
    var
    im=document.getElementById("logo");

    document.write ("doc size= ", document.width, " ", document.height);
    document.write (" im size= ", im.width, " ", im.height);
    document.write (" space= ", im.hspace, " ", im.vspace);
    }
    </script>

    <img id="logo" src="Images/HomeSmall.gif" />

    </body>

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,268
    Don't use document.write after the page is loaded !
    Try this (it's not easy to see withe color text on white background !)
    Code:
    <!doctype html>
    <head>
    <script>
    function Resize(){
        var im=document.getElementById("logo"),chn='';
        chn+="<p>doc size= "+document.body.offsetWidth+" "+document.body.offsetHeight;
        chn+="<br> im size= "+im.width+" "+im.height;
        chn+="<br> space= "+im.hspace+" "+im.vspace+"</p>"; alert(chn)
        document.getElementById('rsp').innerHTML=chn;
    }
    </script>
    </head>
    <body onload="Resize()">
    <img id="logo" src="Images/HomeSmall.gif">
    <div id="rsp"></div>
    </body>
    </html>

  3. #3
    Join Date
    Sep 2013
    Posts
    2
    [QUOTE=007Julien;1289539]Don't use document.write after the page is loaded !
    Try this (it's not easy to see withe color text on white background !)

    Hi, Julien,

    Thanks for the "alert" tip! I'm really a javascript beginner... LOL

    BUT... IE (I use IE 8) keeps returning "undefined" for "document.width" and "document.height". Image width and height are ok. Image "hspace" and "vspace" are returned as 0 (zero), though they have a positive value.

    And in Chrome they keep returning all right...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles