is the following JavaScript valid?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • The Prince
    Confirmed User
    • Apr 2006
    • 158

    #1

    is the following JavaScript valid?

    I am trying to get my site to change the Banner Ads everytime a visitor visits the same page... first it's Nautica's banner then switchs to Mr.Chew's banner when he visits the page again or clicks on back button ... hope you understand what i mean... below is the Java Script.. let me know if there are mistakes...for purposes of illustration/example i didnt put my site's URL and Affiliate#'s for privacy reasons... hope you can help me... :

    <SCRIPT LANGUAGE="javaScript">
    <!--Begin
    var how_many_ads=2;
    var now = new Date()
    var sec = now.getSeconds()
    var ad = sec % how_many_ads;
    ad +=1;
    if (adhahahaha1) {
    txt=" ";
    url="http://refer.ccbill.com/cgi-bin/clicks.cgi?CA=924490-0006&PA=ID#";
    alt="Wanna see Nautica fuck & Suck?, then Click Here";
    banner="http://www.mywebsite.net/Nautica/banners/banner01_460x80.gif";
    width="460";
    height="80";
    }
    if (adhahahaha2) {
    txt=" ";
    url="http://www.mrchewsasianbeaver.com/?wm_login=ID#";
    alt="Wanna see little Asian Beavers get fucked hard?, then Click Here";
    banner="http://www.mywebsite.net/Nautica/banners/MrChewAsianBeaver1.gif";
    width="468";
    height="60";
    }
    document.write('<center>');
    document.write('<a href=\" + url +'\" target=\"_blank\">);
    document.write('<img src=\" + banner + '\" width=')
    document.write(width + 'height=' + height + ' ' );
    document.write('alt=\" + alt + '\" border=0><br>');
    document.write('<small>' + txt + '</small></a>');
    document.write('</center>');
    //End -->
    </SCRIPT>
  • The Prince
    Confirmed User
    • Apr 2006
    • 158

    #2
    bump..... anyone? and if it's not valid... where can i get the correct scripting for such a feature... switching banners as pages are changed by the visitor....

    Comment

    • testpie
      Mostly retired
      • Apr 2006
      • 3231

      #3
      You'd probably be better off getting a PHP solution or using an off-the-shelf JavaScript random banner solution.

      Affiliates: DogFart ~ Domain parking: NameDrive ~ Traffic broker: Traffic Holder

      Comment

      • The Prince
        Confirmed User
        • Apr 2006
        • 158

        #4
        where can i get the off-the-shelf Java one? ..

        Comment

        • testpie
          Mostly retired
          • Apr 2006
          • 3231

          #5
          Originally posted by Lars22
          where can i get the off-the-shelf Java one? ..
          Never mind - i'm feeling so nice this evening i've just coded you one for nowt.
          Just copy and paste the following code (modifying the advert URL, ALT, IMAGE etc.) wherever you want the advert to be shown, and reply here if you have any problems:
          Code:
          <script type="text/javascript" language="JavaScript">
          // Store the advert attributes in arrays
          ad_url = new Array();
          ad_img = new Array();
          ad_alt = new Array();
          
          // For each advert do this (where x is the next available number):
          // ad_url[x] = "URL TO ADVERTISER GOES HERE";
          // ad_img[x] = "URL TO IMAGE GOES HERE";
          // ad_alt[x] = "ALT TO BE DISPLAYED GOES HERE";
          ad_url[0] = "http://refer.ccbill.com/cgi-bin/clicks.cgi?CA=924490-0006&PA=ID#";
          ad_img[0] = "http://www.mywebsite.net/Nautica/banners/banner01_460x80.gif";
          ad_alt[0] = "Wanna see Nautica fuck & Suck?, then Click Here";
          ad_url[1] = "http://www.mrchewsasianbeaver.com/?wm_login=ID#";
          ad_img[1] = "http://www.mywebsite.net/Nautica/banners/MrChewAsianBeaver1.gif";
          ad_alt[1] = "Wanna see little Asian Beavers get fucked hard?, then Click Here";
          // Calculate a random number
          i = Math.floor(Math.random() * ad_url.length);
          
          // Display the advert
          document.write("<a href='" + ad_url[i] + "'><img src='" + ad_img[i] + "' alt='" + ad_alt[i] + "' title='" + ad_alt[i] + "' border='0' /></a>\n");
          </script>

          Affiliates: DogFart ~ Domain parking: NameDrive ~ Traffic broker: Traffic Holder

          Comment

          • The Prince
            Confirmed User
            • Apr 2006
            • 158

            #6
            Thanks alot.. but i just have one question... im not really a Javascript writer.. the one I showed as a example i got from a book.. so for the one you wrote.. where you wrote "X"'s... do i have to put something there? ...

            Comment

            • testpie
              Mostly retired
              • Apr 2006
              • 3231

              #7
              Originally posted by Lars22
              Thanks alot.. but i just have one question... im not really a Javascript writer.. the one I showed as a example i got from a book.. so for the one you wrote.. where you wrote "X"'s... do i have to put something there? ...
              The lines that are preceeded by "//" are comment lines, and are for information purposes only - they are not processed by JavaScript. That was just to show you what you would do, but i put both the banners in just to exemplify it further to.

              In short - no you don't have to change the actual bit with the "X"'s, for each banner just remember you'll need an ad_url[], ad_img[] and ad_alt[] where the number in square brackets is the next available number.

              Affiliates: DogFart ~ Domain parking: NameDrive ~ Traffic broker: Traffic Holder

              Comment

              Working...