IE does not load image when it is specified from JS

Discussion in 'Javascript' started by Royan, Oct 23, 2007.

  1. Royan

    Royan Guest

    Ok this is more then strange but this is how the following code works
    in IE:

    <html>
    <head>
    <meta http-equiv=Content-Type content="text/
    html;charset=windows-1251">
    </head>
    <body>
    <script>
    function reloadImage() {
    var oImg = document.getElementById("myImage");
    oImg.src = "http://www.google.com/images/nav_logo3.png";
    }
    </script>
    <img id="myImage" src="http://us.i1.yimg.com/us.yimg.com/i/ww/beta/
    y3.gif">
    <br/><br/>
    <a href="javascript:;" onClick="reloadImage()">ðÏÍÅÎÑÔØ
    ÉÚÏÂÒÁÖÅÎÉÅ</a>
    </body>
    </html>

    As you can see the browser must simply change Yahoo logo to Google
    logo, but for some reason such code does not work in IE6 (Opera/
    Firefox are OK)
    This is definitely not a problem of changing gif to png as I have
    experimented with two gifs and even jpegs.

    Can anyone explain what am I doing wrong and how do i make this code
    work?
     
    Royan, Oct 23, 2007
    #1
    1. Advertising

  2. Royan

    xprotocol Guest

    On Oct 23, 10:51 am, Royan <> wrote:
    > Ok this is more then strange but this is how the following code works
    > in IE:
    >
    > <html>
    > <head>
    > <meta http-equiv=Content-Type content="text/
    > html;charset=windows-1251">
    > </head>
    > <body>
    > <script>
    > function reloadImage() {
    > var oImg = document.getElementById("myImage");
    > oImg.src = "http://www.google.com/images/nav_logo3.png";
    > }
    > </script>
    > <img id="myImage" src="http://us.i1.yimg.com/us.yimg.com/i/ww/beta/
    > y3.gif">
    > <br/><br/>
    > <a href="javascript:;" onClick="reloadImage()">ðÏÍÅÎÑÔØ
    > ÉÚÏÂÒÁÖÅÎÉÅ</a>
    > </body>
    > </html>
    >
    > As you can see the browser must simply change Yahoo logo to Google
    > logo, but for some reason such code does not work in IE6 (Opera/
    > Firefox are OK)
    > This is definitely not a problem of changing gif to png as I have
    > experimented with two gifs and even jpegs.
    >
    > Can anyone explain what am I doing wrong and how do i make this code
    > work?


    This is strange. It's not just changing the src attribute that's an
    issue, even dynamically appending a brand new image will result in the
    space being occupied but the image not displaying. I've changed the
    src attribute on images numerous times in my web apps with no
    problems. Interestingly, if you right click on the space and goto
    "Show Picture", it will display.
     
    xprotocol, Oct 23, 2007
    #2
    1. Advertising

  3. Royan

    Henry Guest

    On Oct 23, 3:51 pm, Royan wrote:
    <snip>
    > <a href="javascript:;" onClick="reloadImage()">

    <snip>
    > Can anyone explain what am I doing wrong and how do i make
    > this code work?


    Executing a javascript pseudo protocol HREF in IE puts the browser
    into a 'pending navigation' state (in which it stays until real
    navigation occurs). In this state various facilities no longer work
    (or work as expected), including the fetching of new image resources
    for the page (from a server or from the cache).
     
    Henry, Oct 23, 2007
    #3
  4. Royan

    Royan Guest

    On 23 ÏËÔ, 20:07, Henry <> wrote:
    > On Oct 23, 3:51 pm, Royan wrote:
    > <snip>
    >
    > > <a href="javascript:;" onClick="reloadImage()">

    > <snip>
    > > Can anyone explain what am I doing wrong and how do i make
    > > this code work?

    >
    > Executing a javascript pseudo protocol HREF in IE puts the browser
    > into a 'pending navigation' state (in which it stays until real
    > navigation occurs). In this state various facilities no longer work
    > (or work as expected), including the fetching of new image resources
    > for the page (from a server or from the cache).


    Yes thats correct and this is exactly whats happening, so replacing
    href value with the wollowing href="#" or simply removing it fixes the
    issue
     
    Royan, Oct 23, 2007
    #4
  5. Royan wrote:
    > Ok this is more then strange but this is how the following code works
    > in IE:
    >
    > [fantasy code]


    Using Valid markup might help. http://validator.w3.org/


    PointedEars
    --
    "Use any version of Microsoft Frontpage to create your site. (This won't
    prevent people from viewing your source, but no one will want to steal it.)"
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm>
     
    Thomas 'PointedEars' Lahn, Oct 23, 2007
    #5
  6. Royan wrote:
    > On 23 окт, 20:07, Henry <> wrote:
    >> On Oct 23, 3:51 pm, Royan wrote:
    >>> <a href="javascript:;" onClick="reloadImage()">

    >> <snip>
    >>> Can anyone explain what am I doing wrong and how do i make
    >>> this code work?

    >> Executing a javascript pseudo protocol HREF in IE puts the browser
    >> into a 'pending navigation' state (in which it stays until real
    >> navigation occurs). In this state various facilities no longer work
    >> (or work as expected), including the fetching of new image resources
    >> for the page (from a server or from the cache).

    >
    > Yes thats correct and this is exactly whats happening, so replacing
    > href value with the wollowing href="#" or simply removing it fixes the
    > issue


    But it introduces at least one other. Correct is:

    <script type="text/javascript">
    document.write('<a href="" onclick="reloadImage(); return false;">'
    + '...<\/a>');
    </script>

    Of course it would be better would an `input' element be used in the first
    place:

    <script type="text/javascript">
    document.write('<input value="..." onclick="reloadImage();">');
    </script>


    PointedEars
    --
    Prototype.js was written by people who don't know javascript for people
    who don't know javascript. People who don't know javascript are not
    the best source of advice on designing systems that use javascript.
    -- Richard Cornford, cljs, <f806at$ail$1$>
     
    Thomas 'PointedEars' Lahn, Oct 23, 2007
    #6
  7. Royan

    xprotocol Guest

    On Oct 23, 2:50 pm, Royan <> wrote:
    > On 23 ÏËÔ, 20:07, Henry <> wrote:
    >
    > > On Oct 23, 3:51 pm, Royan wrote:
    > > <snip>

    >
    > > > <a href="javascript:;" onClick="reloadImage()">

    > > <snip>
    > > > Can anyone explain what am I doing wrong and how do i make
    > > > this code work?

    >
    > > Executing a javascript pseudo protocol HREF in IE puts the browser
    > > into a 'pending navigation' state (in which it stays until real
    > > navigation occurs). In this state various facilities no longer work
    > > (or work as expected), including the fetching of new image resources
    > > for the page (from a server or from the cache).

    >
    > Yes thats correct and this is exactly whats happening, so replacing
    > href value with the wollowing href="#" or simply removing it fixes the
    > issue


    Tried href="#" and it works ok except it causes a slight scroll down
    on the page. Are there other options here? I don't want to remove
    the href attribute because then the anchor won't keep the standard
    look (ie underline, blue, purple when clicked).
     
    xprotocol, Oct 26, 2007
    #7
  8. xprotocol wrote:
    > Tried href="#" and it works ok except it causes a slight scroll down
    > on the page. Are there other options here?


    Reading and implementing what was posted before would be a good idea.

    <>
    news:


    PointedEars
    --
    "Use any version of Microsoft Frontpage to create your site. (This won't
    prevent people from viewing your source, but no one will want to steal it.)"
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm>
     
    Thomas 'PointedEars' Lahn, Oct 26, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Buchan
    Replies:
    0
    Views:
    3,595
    Kevin Buchan
    Feb 16, 2004
  2. Brad
    Replies:
    1
    Views:
    26,413
    [MSFT]
    Jun 22, 2004
  3. Sanmic
    Replies:
    1
    Views:
    3,811
    Scott Allen
    Oct 11, 2004
  4. =?Utf-8?B?TG93ZWxs?=

    IIS won't load ASP.NET, "specified metadata not found"

    =?Utf-8?B?TG93ZWxs?=, Nov 18, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    11,527
    ntaborda
    Aug 2, 2012
  5. Bill Davy
    Replies:
    2
    Views:
    19,767
    Bill Davy
    Jun 1, 2005
Loading...

Share This Page