IE does not load image when it is specified from JS

R

Royan

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?
 
X

xprotocol

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.
 
H

Henry

On Oct 23, 3:51 pm, Royan wrote:
<a href="javascript:;" onClick="reloadImage()">
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).
 
R

Royan

On Oct 23, 3:51 pm, Royan wrote:



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
 
T

Thomas 'PointedEars' Lahn

Royan said:
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
 
X

xprotocol

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).
 
T

Thomas 'PointedEars' Lahn

xprotocol said:
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.

<[email protected]>


PointedEars
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top