SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Non-Member Webby007's Avatar
    Join Date
    Sep 2005
    Location
    UK, England
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Need Script: Rotate Banner Every x Seconds - But Show Random 1st Banner Every Refresh

    Hi,

    I'm looking for a Javascript Solution - That allows me to rotate banners on a webpage without the need to refresh the page. So it automatically roattes every x amount of seconds.

    Also I would like the banners to be random every page refresh. i.e - the same banner doesn't show first every time.

    Can anyone help me with a solution please?

    Many thanks.

    Webby

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    There is a wealth of these on google: http://www.google.co.uk/search?hl=en...script&spell=1

  3. #3
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    resim0.bmp
    resim1.bmp
    resim2.bmp
    resim3.bmp

    Code:
      
    <html><head>
    </head>
    <body>
     
    <div id="div1"></div>
    
    
    <script type=text/javascript>
    
    var t=0;
    function next(){
    
    var div1 = document.getElementById('div1');
    
    div1.innerHTML='<img width="100" height="100" src="resim'+ t + '.bmp" ></img>'
    
    t++
    
    if (t==4){t=0}
    
    setTimeout("next()",3000)
    }
    next();
    
    </script>
    </body>
    </html>
    Last edited by muazzez; Jan 22, 2007 at 07:52.

  4. #4
    Non-Member Webby007's Avatar
    Join Date
    Sep 2005
    Location
    UK, England
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you both for the replies.

    muazzez: how can I specify different url's for each banner please?


  5. #5
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
      
    <html><head>
    </head>
    <body>
     
    <div id="div1"></div>
    
    
    <script type=text/javascript>
    
    var t=0;
    function next(){
    
    var div1 = document.getElementById('div1');
    
    div1.innerHTML='<a href="resim'+t+'.bmp" target="_blank">resim'+t+'<img width="100" height="100" src="resim'+ t + '.bmp" ></img></a>'
    
    t++
    
    if (t==4){t=0}
    
    setTimeout("next()",3000)
    }
    next();
    
    </script>
    </body>
    </html>
    mypage0.htm
    mypage1.htm
    ...
    Code:
      
    <html><head>
    </head>
    <body>
     
    <div id="div1"></div>
    
    
    <script type=text/javascript>
    
    var t=0;
    function next(){
    
    var div1 = document.getElementById('div1');
    
    div1.innerHTML='<a href="mypage'+t+'.htm" target="_blank"><img width="100" height="100" src="resim'+ t + '.bmp" ></img></a>'
    
    t++
    
    if (t==4){t=0}
    
    setTimeout("next()",3000)
    }
    next();
    
    </script>
    </body>
    </html>
    Code:
      
    <html><head>
    </head>
    <body>
     
    <div id="div1"></div>
    
    
    <script type=text/javascript>
    
    var arr = new Array(
    
    "aa.htm",
    "bb.htm",
    "cc.htm",
    "dd.htm"
    );
    var t=0;
    function next(){
    
    var div1 = document.getElementById('div1');
    
    div1.innerHTML='<a href=" '+arr[t]+' " target="_blank"><img width="100" height="100" src="resim'+ t + '.bmp" ></img></a>'
    
    t++
    
    if (t==4){t=0}
    
    setTimeout("next()",3000)
    }
    next();
    
    </script>
    </body>
    </html>
    Code:
      
    <html><head>
    </head>
    <body>
     
    <div id="div1"></div>
    
    
    <script type=text/javascript>
    
    var arr = new Array(
    
    "aa.htm",
    "bb.htm",
    "cc.htm",
    "dd.htm"
    );
    var banner = new Array(
    "zz.jpg",
    "yy.jpg",
    "vv.jpg",
    "uu.jpg"
    );
    var t=0;
    function next(){
    
    var div1 = document.getElementById('div1');
    
    div1.innerHTML='<a href=" '+arr[t]+' " target="_blank"><img width="100" height="100" src=" '+banner[t] + ' " ></img></a>'
    
    t++
    
    if (t==4){t=0}
    
    setTimeout("next()",3000)
    }
    next();
    
    </script>
    </body>
    </html>
    in this page ( www.huntingground.net )
    click image scripts
    Last edited by muazzez; Jan 22, 2007 at 08:46.

  6. #6
    Non-Member Webby007's Avatar
    Join Date
    Sep 2005
    Location
    UK, England
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Thank you very much for the code.

    At present i'm trying this script:

    Javascript:

    PHP Code:
    var banners = new Array(
        
    'banner1.jpg',
        
    'banner2.jpg',
        
    'banner3.jpg');
    var 
    linx = new Array(
        
    'http://www.sitepoint.com',
        
    'http://www.sitepoint.com',
        
    'http://www.sitepoint.com');
    var 
    old 0;
    var 
    current 0;

    function 
    init()
    {
        if (!
    document.images) return
        while (
    current == old)
        {
            
    current Math.floor(Math.random()*banners.length);
        }
        
    old current;
        
    document.images['banner'].src banners[current];
        
    setTimeout('init()',2000);
    }

    function 
    sendPage()
    {
        
    location.href linx[current];

    HTML

    HTML Code:
    <html>
    <head>
    <script type="text/javascript" src="banners.js"></script>
    </head>
    
    <body onload="init()">
    <a href="javascript:sendpage()"><img src="banner1.jpg" name="banner" width=485 height=78 border=0></a>
     
    </body>
    </html>
    Everything works, except for the link, it's not clickable - i get this on hover, javascript:sendpage - rather than the link specified in the javascript. This normally happens when a function isn't defined, but as you can see in the code it is.

    So once the link is fixed, this should be a good solution!

    Can any Javascript whizz's help me out please?

    Many thanks

    Webby

  7. #7
    Non-Member Webby007's Avatar
    Join Date
    Sep 2005
    Location
    UK, England
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Solved: javascript:sendpage should be: javascript:sendPage

    Just a small typo! - it's always the way!

    Cheers.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •