insert a ns4/ie switch in a script


I have the following script:

var imgObj = null;
var openImg = new Image();
var closeImg = new Image();
function PixelVposition(thelayername,imgName){
    var newImgObj = document.layers[thelayername].document.images[imgName];
         if(imgObj) {
              if(imgObj != newImgObj){
                   imgObj.src = closeImg.src;
                   newImgObj.src= openImg.src;
              newImgObj.src= openImg.src;      
    imgObj = newImgObj;      

It works good for ns4 but for ie I have to set the "var newImgObj" to:

var newImgObj = document.images[imgName];

instead to make it work in ie

How can I insert a "switch" in the script to set the correct variable for ie?
Also, will I get access to the image on the layer also in NS6?

Kind Regards
Joergen Astroem
Who is Participating?
ahosangConnect With a Mentor Finance Systems DeveloperCommented:
var newImgObj = (document.layers)?document.layers[thelayername].document.images[imgName]:document.images[imgName];
jastroemAuthor Commented:
thanks a lot - works just fine
I forgot to grade your answer...
Kind Regards
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.