Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts

    IE weird javascript console ...

    In IE 6 WIN I got a js console error message saying that an object is expected when writng the script like this:


    Code:
    <script type="text/javascript">
    document.getElementById('largeImage').onload=function(){
    unhideAllDivs ();
    }
    </script>
    In IE 6 WIN doing this no js errors any more

    Code:
    <script type="text/javascript">
    var document.getElementById('largeImage') = 'largeImg' ;
    largeImg.onload=function(){
    unhideAllDivs ();
    }
    </script>
    What caused the error in the version without the declared var in IE 6 WIN ?
    Is there a better way to write this?
    Last edited by _com; 07-09-2005 at 06:04 PM.

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,501
    Thanks
    3
    Thanked 500 Times in 487 Posts
    answered wrong post
    Last edited by vwphillips; 07-09-2005 at 05:20 PM.

  • #3
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,501
    Thanks
    3
    Thanked 500 Times in 487 Posts
    best try and say somthing after above

    but I have no idea what

    var document.getElementById('largeImage') = 'largeIm' ;
    is trying to achieve

    but if you are trying to load a large image

    this will change the image if it is found
    but probably before its loaded

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    
    function PreLoad(){
    largeIm=new Image();
    largeIm.onload=function(){ document.getElementById('largeImage').src=largeImg.src; unhideSmalDivs (); }
    largeIm.src='MyImage.jpg';
    }
    </script>
    </head>
    
    <body>
    
    </body>
    
    </html>

  • #4
    Regular Coder
    Join Date
    Mar 2005
    Posts
    195
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No, this code snippet is to execute the script unhideAllDivs AFTER the image with id=largeImage has loaded.

    My question was if it makes any difference if I would declare a variable
    Code:
    var largeImg = document.getElementbyId('largeImage');
    .

    The javascript console that popped up in IE6 WIN XP gave an error saying object wass missing so that is why I put in an extra line to declare the var.

    Will the var be set to null by itself after execution of the function?
    Last edited by _com; 07-09-2005 at 06:07 PM.


  •  

    Posting Permissions

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