Jump to content

Recommended Posts

Howdy,

I am trying to place three instances of a 'scrpt' on my page to rotate the same three banners in different orders, when I put it in the second time I get a background but no banners. can anyone tell me what I am doing wrong or how to make it work (changed the link names for privacy)

 

 <p>
            <script language="JavaScript1.2">



var variableslide=new Array()
variableslide[0]=['Images/image1.gif','Http://www.msn.com',']
variableslide[1]= ['Images/image2.gif','Http://www.msn.com',']
variableslide[2]= ['Images/image3.gif','Http://www.msn.com',']
var slidewidth='320x'
var slideheight='50px'
var slidebgcolor='#252A54'
var slidedelay=7000
var ie=document.all
var dom=document.getElementById
for (i=0;i<variableslide.length;i++){
var cacheimage=new Image()
cacheimage.src=variableslide[0]
}
var currentslide=0
function rotateimages(){
contentcontainer='<center>'
if (variableslide[currentslide][1]!="")
contentcontainer+='<a href="'+variableslide[currentslide][1]+'">'
contentcontainer+='<img src="'+variableslide[currentslide][0]+'" border="0" vspace="3">'
if (variableslide[currentslide][1]!="")
contentcontainer+='</a>'
contentcontainer+='</center>'
if (variableslide[currentslide][2]!="")
contentcontainer+=variableslide[currentslide][2]
if (document.layers){
crossrotateobj.document.write(contentcontainer)
crossrotateobj.document.close()
}
else if (ie||dom)
crossrotateobj.innerHTML=contentcontainer
if (currentslide==variableslide.length-1) currentslide=0
else currentslide++
setTimeout("rotateimages()",slidedelay)
}
if (ie||dom)
document.write('<div id="slidedom" style="width:'+slidewidth+';height:'+slideheight+'; background-color:'+slidebgcolor+'"></div>')
function start_slider(){
crossrotateobj=dom? document.getElementById("slidedom") : ie? document.all.slidedom : document.slidensmain.document.slidenssub
if (document.layers)
document.slidensmain.visibility="show"
rotateimages()
}
if (ie||dom)
start_slider()
else if (document.layers)
window.onload=start_slider
</script>
<ilayer id="slidensmain" width=&{slidewidth}; height=&{slideheight}; bgColor=&{slidebgcolor}; visibility=hide><layer id="slidenssub" width=&{slidewidth}; left=0 top=0></layer></ilayer>          </p>

Link to comment
https://forums.phpfreaks.com/topic/286209-having-trouble-with-javascript/
Share on other sites

I'd suggest you find some updated code that does what you want. That code is like late-90's era (NS4/IE5) code. Aside from being old it's not written in such a way that you can just copy and paste multiple copies of it into a page. You'd need to rewrite it to remove it's dependence on global variables for that to work.

Try,

 

page.html

<!DOCTYPE html>
<html lang="en">
    <head>  
        <script type="text/javascript" src="js/rotate.js"></script>

        <title>Banner test page</title>

    </head>

    <body>

        <div>
            <a href="http://msn.com">
                <img src="Images/1.jpg" alt="some image" id="adBanner" />
            </a>
        </div>
    </body>
</html>

Images folder (images/)

 

 

image1.gif

image2.gif
 

image3.gif

 

rotate.js (js/rotate.js)

window.onload = choosePic;

var adImages = new Array("Images/image1.gif","Images/image2.gif","Images/image3.gif");

function rotate() {
      thisAd++;
      if (thisAd == adImages.length) {
         thisAd = 0;
      }
      document.getElementById("adBanner").src = adImages[thisAd];

      setTimeout("rotate()", 3 * 1000);

}

function choosePic() {
      thisAd = Math.floor((Math.random() * adImages.length));
      document.getElementById("adBanner").src = adImages[thisAd];

      rotate();
} 
Edited by jazzman1

Sorry, I'm not here to write all code for you. It was a simple example how to make some picture rotation using js. Everything you need is, to pick up some js slideshow library with a banner rotation. 

Take a look at those examples.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.