Results 1 to 3 of 3

Thread: Image swap with JavaScript vs. IE7

  1. #1
    Join Date
    May 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Image swap with JavaScript vs. IE7

    1) Script Title:

    showFilterButtons

    2) Script URL :

    www.roberto-colombo.com

    3) Describe problem:

    Hello,

    I have been reported a bug on my script (working well with Netscape, IE5 etc.) with IE7.
    A JS function simply change the image url, allowing to change the displayed image.
    Something like:

    if ( document.getElementById ) // IE5+ & Gecko
    {
    if ( document.getElementById( id ).innerHTML != null )
    {
    document.getElementById( id ).innerHTML.src = url;
    }
    }
    else if ( document.getElementById ) // IE5+ & Gecko
    {
    if ( document.getElementById( id ) != null )
    {
    document.getElementById( id ).src = url;
    }
    }
    else if (document.all) // IE4
    {
    if ( document.all[ id ] != null )
    {
    document.all[ id ].src = url;
    }
    }
    else // Netscape 4
    {
    if ( document.images[ id ] != null )
    {
    document.images[ id ].src = url;
    }
    }

    With IE7, this seems not working, no image is displayed. :-||
    Of course, the "id" points to a valid image id, which is referenced in the HTML within the <img> tag.
    Also, the same image id is created in JavaScript with the new Image() call.
    In fact everything works fine with IE5, Netscape... did I miss anything regarding IE7 ?
    Is there anythnig that should be changed ?
    Can I still use document.getElementById in the same way ?

    :-|

    HELP...
    Last edited by jscheuer1; 05-05-2007 at 04:57 PM. Reason: Not a DD script

  2. #2
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default

    Uhh...
    I've noticed that IE7 throws almost all scripts out of wack.
    ....(o_ Penguins
    .---/(o_- techno_racing
    +(---//\-' in
    .+(_)--(_)' The McMurdo 500

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by RobertoShanghai View Post
    if ( document.getElementById ) // IE5+ & Gecko
    {
    if ( document.getElementById( id ).innerHTML != null )
    {
    document.getElementById( id ).innerHTML.src = url;
    }
    }
    else if ( document.getElementById ) // IE5+ & Gecko
    {
    if ( document.getElementById( id ) != null )
    {
    document.getElementById( id ).src = url;
    }
    }
    else if (document.all) // IE4
    {
    if ( document.all[ id ] != null )
    {
    document.all[ id ].src = url;
    }
    }
    else // Netscape 4
    {
    if ( document.images[ id ] != null )
    {
    document.images[ id ].src = url;
    }
    }
    What on Earth is all that lot for? The images collection is (more-or-less) universal and preferred, not a legacy NN4 property:

    Code:
    if (document.images)
        document.images[id].src = url;
    Note that NN4 won't support this anyway as it has limited knowledge of the id attribute. If each img element has a name attribute with a value that matches the id attribute, then it would work.

    With IE7, this seems not working, no image is displayed. :-||
    I'm rather surprised that the first code branch works with anything, considering that the innerHTML property is a string, and strings have no src property.

    Mike

Bookmarks

Posting Permissions

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