PDA

View Full Version : Gallery JS wont work in IE?



skepticstudios
August 15th, 2006, 12:18 PM
Im helping out a friend and making a gallery for them with JavaScript, it works fine in every browser - except surprise surprise IE 6

http://www.bobvideo.co.uk/os/gmj/earth.html

That is a link to the gallery, Im currently viewing in Opera 9 and its working perfectly. This is the script:



<script type="text/javascript" language="javascript">
function showPic (whichpic) {
if (document.getElementById) {
document.getElementById('placeholder').src = whichpic.href;
if (whichpic.title) {
document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
} else {
document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
}
return false;
} else {
return true;
}
}
</script>


The placeholder code is:


<p id="desc"> </p>
<img src="images/gallery/earth/earth1.jpg" alt="" id="placeholder"/>

The code for a single thumbnail is:



<ul>
<li><a onclick="return showPic(this)" href="images/gallery/earth/earth1.jpg" title="Earth 1">
<img class="thumb" src="images/gallery/earth/earth1_p.jpg"></a></li>
</ul>


When you click on a thumbnail in IE the larger image opens in a new window, why is this happening?

aldomatic
August 15th, 2006, 01:24 PM
this script looks like one out of the DOM scripting book? if so should work with IE 6 aswell


onclick="return showPic(this); return false;

zerokilled
August 15th, 2006, 08:15 PM
hi

your problem seem to be complex to track because previously I had disabled the built-in debugger from IE6. however, the debugger return me that the following code is null or not an object:


document.getElementById('desc').childNodes[0]
I don't know if this is an obvious behavior or not, but as you may possible know every browser remove any extra white space when rendering the content. So, this is exactly what is happening, the p id='desc' element have an white space. Hence, in IE6 the script can't look over that element and the function fail returning no value, so the href attribute take presendence over the function. my suggestion is to force the browser to display a white space &nbsp; The problem isn't the script, is the browser's behavior.

skepticstudios
August 16th, 2006, 06:00 AM
thats great zk, I'll have a look at the script and code and see what I can do with that

skepticstudios
August 16th, 2006, 06:59 AM
That works perfect now ZK, thanks a lot!