What is the best way to code a rotating banner advertisement?

Discussion in 'HTML & Website Design' started by IanT, Jul 16, 2010.

  1. #1
    What is the best way? In terms of accessibility across different browsers, Javascript? PHP?


    The current thing I have been testing is right here:


    http://www.smftutorials.com/testing/template.html

    But I dont like that it goes from the images to the text and makes the page shrink etc...

    My idea is to cut down on text that the users need to read, and add more graphic stimulation... (I dont know if thats a good idea or what... the currently deployed site is here: www.smftutorials.com , but its poo brown and I like the updated color scheme way better)

    I was going to use php but I ran into a hiccup because I dont want to lose my google rankings by switching the coding to php (and hence invalidating like 4000+ backlinks... ) I have heard you can redirect the bad pages or something but I have no idea how to do that (so Id need a tut or something??)


    If I wanted to keep it in html I could use javascript, but Im worried about the accessibility and having something that will show up instead of the images should someone not have javascript enabled...

    so whats the consensus ? whats should I do?

    thanks!


    :)
     
    IanT, Jul 16, 2010 IP
  2. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #2
    Well, PHP would've been easy, but since you're worried of your google ranking, javascript's ain't a bad idea as well. But as you've said, accessibility is unavoidable - you have to understand that with javascript, the user has the full control of it.

    It wouldn't hurt with PHP in my honest opinion, I don't believe it's gonna hurt your ranking. Give it a try, study a bit of it and see. Because with PHP you will have more control over the user.
     
    Rainulf, Jul 16, 2010 IP
  3. daftone

    daftone Banned

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    you can try iframes. Use code to rotate the frame/banner that is in the iframe.
     
    daftone, Jul 16, 2010 IP
  4. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Create a page that just has a simple div and some javascript that polls (this is Ajax) a PHP script every 30 seconds or so. The PHP script returns a random banner URL. The javascript then uses that URL to update the div.

    Then, you put this code where ever you want with an iFrame.

    or make the entire thing a PHP script that generates the banner HTML (with a random banner) every time it's loaded and stick a meta refresh in the header. :)
     
    Deacalion, Jul 16, 2010 IP
  5. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #5
    PHP script to generate random banner (for iframe):
    
    <?php
        // seconds between each banner  
        $seconds = 5;   
        
        // the banners
        $banners = array(
            'http://www.happycow.net/banner/468x60.gif'                                => 'http://www.google.com/', 
            'http://www.visitneamt.com/wp-content/uploads/banners/Neamt468-60_en6.jpg' => 'http://www.amazon.com/',
            'http://bipbanners.co.uk/assets/images/Fantazee_Full_Static_Banner_2A.gif' => 'http://www.ebay.com/'
            // Keep adding as many as you want here
        );
        
        $img  = array_rand($banners);
        $link = $banners[$img]; 
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
    
    <html>
    
        <head>
    
            <title>My Banner</title>
            <meta http-equiv="refresh" content="<?php echo $seconds; ?>" />
        </head>
    
        <body>
            <a href="<?php echo $link; ?>"><img src="<?php echo $img; ?>" alt="Click this banner!" /></a>
        </body>
    </html>
    
    PHP:
    Then you can put this iFrame anywhere else you want:
    
    <iframe src="http://www.MySite.co.uk/bannerScript.php" name="banner" scrolling="no" frameborder="no" align="center" height="60px" width="468px">
    </iframe>
    
    HTML:
     
    Deacalion, Jul 16, 2010 IP
  6. IanT

    IanT Well-Known Member

    Messages:
    503
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    130
    #6
    Thanks for the replies!

    Okay, I tried the script example you gave above and it seems to be showing up weird, there is a blue border around the whole thing and then only parts of the ads are displayed....

    Right now I may stay with .js but not sure... anyhoo... supposing I DO stick to that, is there a way to add an alt which is invisible to all but .js-off users??

    Here is the example I have up now:

    http://www.smftutorials.com/testing/template.html

    but its funky, sentences start popping up instead of words ...etc


    how can I improve this script?? also can I use an include so as not to have to have the js all over the place?

    thanks for the help!
     
    IanT, Jul 16, 2010 IP
  7. ackernik

    ackernik Greenhorn

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #7
    javascript?
     
    ackernik, Jul 17, 2010 IP
  8. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Add this between the head tags:
    
    <style type="text/css">
        body{margin:0;padding:0}
        img{border-style: none}
    </style>
    
    HTML:
     
    Deacalion, Jul 18, 2010 IP