Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

image swap

Status
Not open for further replies.

Sarky78

Programmer
Oct 19, 2000
878
GB
I have got a standard bit of code that pre-loads the images to use on the page, and then a bit of code that will swap them when a thumbnail is clicked. The actual main image is positioned using a <DIV> tag with positioning elements on it. This all works fine in IE, but when i put it near to Netscape, it all goes wrong. It just stops working, its doesn't swap the image. I have taken the image out of the <DIV> and it works, but is not in the right place.

Is there anyway that I can get this to work in NS ??

This is the code that is being used:

Javascript:
function changePic(imgName) {
if (document.images) {
document['detail'].src = eval(imgName + &quot;.src&quot;);
}
}

main Image code
<DIV id=&quot;wwbg1&quot; style=&quot;position:absolute; width:200px; height:115px; z-index:3; left: 6px; top: 49px&quot;>
<IMG src=&quot;pixels/ww/ww0.jpg&quot; width=&quot;269&quot; height=&quot;304&quot; name=&quot;detail&quot;>
</div>

Any help would be apreciated !!
 
You will need to interogate the browser and then setup a function which either writes a DIV & IMG combo(MSIE) or a LAYER tag(NN) with the background property set to the file location.
step 1.
in the HEAD tags setup script that can determine the browser in use.

if (parseInt(navigator.appVersion.charAt(0)) >= 4)
{
if (navigator.appName == &quot;Netscape&quot;)
{
isIE4 = false;
}
else if (navigator.appVersion.indexOf(&quot;MSIE&quot;) != -1)
{
isIE4 = true;
}
else
location = &quot;nogo.html&quot;;
}

step 2.
setup the function which will either write a DIV or LAYER tag.

function setupDIV(classname, idname, text, isImg)
{
var obj = &quot;<DIV class='&quot; + classname + &quot;' ID='&quot; + idname + &quot;'>&quot;;
obj += &quot;<IMG SRC='&quot; + text + &quot;'>&quot;;
obj += &quot;</DIV>&quot;;
if (!isIE4)
{
var obj = &quot;<LAYER class='&quot; + classname + &quot;'
ID='&quot; + idname + &quot;' BACKGROUND='&quot; + text + &quot;'>&quot;;
}

document.write(obj);
}
step 3.
Change your function to be browser aware.

function changePic(imgName)
{
if (document.images)
{
if (isIE4)
{
document['detail'].src = eval(imgName + &quot;.src&quot;);
}
else
{
document.LayerID.background = eval(imgName + &quot;.src&quot;);
}
}
}

 
sorry, change the setupDIV function to be this:

function setupDIV(classname, idname, text, isImg)
{
if (!isIE4)
{
var obj = &quot;<LAYER class='&quot; + classname + &quot;'
ID='&quot; + idname + &quot;' BACKGROUND='&quot; + text + &quot;'>&quot;;
}
else
{
var obj = &quot;<DIV class='&quot; + classname + &quot;'
ID='&quot; + idname + &quot;'>&quot;;
obj += &quot;<IMG SRC='&quot; + text + &quot;'>&quot;;
obj += &quot;</DIV>&quot;;

}

document.write(obj);
}
 
Cheers for that i'll give that a try, or just talk the client to dump netscape. I take it that you have experienced a problem like this in the past then !!!

I can't believe that there is not an easier work around !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top