Forum Moderators: not2easy
Could you please tell me how I can get imageA and imageB to change over in Netscape 7.1. My code works well in Netscape 4.7 and Microsoft Internet Explorer 6.0, but I cannot succeed in getting the graphics to change over in Netscape 7.1
My JS code is placed below.
Many thanks in advance.
Best wishes,
Robin
NZ
<script type="text/javascript">
<!--
var imageA = new Image()
imageA.src = "imageA.gif"
var imageB = new Image()
imageB.src = "imageB.gif"
function changeToB()
{
if (document.all)
{
document.images['BoxImage'].src=imageB.src;
}
if (document.layers)
{
document.Box.document.images['BoxImage'].src=imageB.src;
}
if (document.getElementById)
{
document.getElementById.images('BoxImage').src=imageB.src
}
}
function changeToA()
{
if (document.all)
{
document.images['BoxImage'].src=imageA.src;
}
if (document.layers)
{
document.Box.document.images['BoxImage'].src=imageA.src;
}
if (document.getElementById)
{
document.getElementById.images('BoxImage').src=imageA.src
}
}
// -->
</script>
<script type="text/javascript">
<!--
imgs = new Array();
imgs[0] = "imageA.gif";
imgs[1] = "imageB.gif";
function changeTo(n) {
--n;
if (document.layers) {
document.Box.document.images['BoxImage'].src=imgs[n];
}
else {
document.images['BoxImage'].src=imgs[n];
}
}
// -->
</script>
Give that a try. Don't need the new Image() constructor since you are just changing the src attribute of existing images. Will use a bit less memory this way as well.
Other thing is make the images an array, then you can just use one function (make sure you get the
--n part in to substract one from n since the array is zero-based). Then just call it like changeTo(1); Hope that helps.
Jordan
========
* Changed to reflect msr986's suggestion.