How can i create Adsense rotator code with Javascript

Discussion in 'AdSense' started by BNix, Jun 12, 2006.

  1. #1
    Hi All
    I've created javascript code to rotate Adbrite and Adsense

    The Code is applied from

    http://blog.360.yahoo.com/blog-zwwMZhwwdrSyXD8-?p=148

    
    var randomnumber=Math.floor(Math.random()*101)
    if(randomnumber>50){ 
    // START ADBRITE ADS
    document.write("<!-- Begin: AdBrite --><style type=\"text/css\">.adHeadline {font: bold 10pt Arial; text-decoration: underline; color:#0000ff;}.adText {font: normal 10pt Arial; text-decoration: none; color:#000000;}</style><script type=\"text/javascript\" src=\"http://4.adbrite.com/mb/text_group.php?sid=111130&amp;col=5&amp;br=1&amp;dk=776569676874206c6f73735f355f325f776562\"></script><p /><div><a class=\"adHeadline\" target=\"_top\" href=\"http://www.adbrite.com/mb/commerce/purchase_form.php?opid=111130&amp;afsid=1\">Your Ad Here</a></div><!-- End: AdBrite -->");
    // END ADBRITE ADS
     } else { 
    // BEGIN ADSENSE ADS
    var googlead = "\
    <script type=\"text/javascript\"><!--\n\
    google_ad_client = \"pub-xxxxxxxxxxxxxxxxxx\";\n\
    google_ad_width = 728;\n\
    google_ad_height = 90;\n\
    google_ad_format = \"728x90_as\";\n\
    google_ad_type = \"text_image\";\n\
    google_ad_channel =\"\";\n\
    google_color_border = \"ffffff\";\n\
    google_color_bg = \"ffffff\";\n\
    google_color_link = \"0000FF\";\n\
    google_color_text = \"000000\";\n\
    google_color_url = \"999999\";\n\
    //--><\/script>\n\
    <script type=\"text/javascript\"\n\
      src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">\n\
    <\/script>\n\
    ";
    document.write(googleads);
    }
    // END ADSENSE ADS
    
    Code (markup):
    It's okay when show Adbrite , but nothing display when show Adsense.

    The reason why i must use javascript is
    Invision power board template didn't allow me to insert php tag.

    Is there anyway to implement adsense with javascript ? Thanks
     
    BNix, Jun 12, 2006 IP
  2. megahertza

    megahertza Peon

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Are you able to mod the backend on invision boards. I'd say thats the only way to implement php into it
     
    megahertza, Jun 12, 2006 IP
  3. BNix

    BNix Peon

    Messages:
    224
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes , I've every permission , but i don't know how to do it
     
    BNix, Jun 13, 2006 IP
  4. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can't use JS to display adsense adverts. They need to be hard coded (using html/php) into the page.
     
    mad4, Jun 13, 2006 IP
  5. amnezia

    amnezia Peon

    Messages:
    990
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #5
    there is an error in the name of your variable

    try this:
    var randomnumber=Math.floor(Math.random()*101)
    if(randomnumber>50){ 
    // START ADBRITE ADS
    document.write("<!-- Begin: AdBrite --><style type=\"text/css\">.adHeadline {font: bold 10pt Arial; text-decoration: underline; color:#0000ff;}.adText {font: normal 10pt Arial; text-decoration: none; color:#000000;}</style><script type=\"text/javascript\" src=\"http://4.adbrite.com/mb/text_group.php?sid=111130&amp;col=5&amp;br=1&amp;dk=776569676874206c6f73735f355f325f776562\"></script><p /><div><a class=\"adHeadline\" target=\"_top\" href=\"http://www.adbrite.com/mb/commerce/purchase_form.php?opid=111130&amp;afsid=1\">Your Ad Here</a></div><!-- End: AdBrite -->");
    // END ADBRITE ADS
     } else { 
    // BEGIN ADSENSE ADS
    var googleads = "\
    <script type=\"text/javascript\"><!--\n\
    google_ad_client = \"pub-xxxxxxxxxxxxxxxxxx\";\n\
    google_ad_width = 728;\n\
    google_ad_height = 90;\n\
    google_ad_format = \"728x90_as\";\n\
    google_ad_type = \"text_image\";\n\
    google_ad_channel =\"\";\n\
    google_color_border = \"ffffff\";\n\
    google_color_bg = \"ffffff\";\n\
    google_color_link = \"0000FF\";\n\
    google_color_text = \"000000\";\n\
    google_color_url = \"999999\";\n\
    //--><\/script>\n\
    <script type=\"text/javascript\"\n\
      src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">\n\
    <\/script>\n\
    ";
    document.write(googleads);
    }
    // END ADSENSE ADS
    Code (markup):
     
    amnezia, Jun 13, 2006 IP
    BNix likes this.
  6. BNix

    BNix Peon

    Messages:
    224
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks a lot , amnezia
    How can i forgot this !
     
    BNix, Jun 14, 2006 IP
  7. Scriptona

    Scriptona Notable Member

    Messages:
    4,957
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    280
    #7
    but this way you edited the adsense code and that is against Adsense TOS
     
    Scriptona, Sep 16, 2006 IP
  8. Tyler Banfield

    Tyler Banfield Well-Known Member

    Messages:
    3,027
    Likes Received:
    173
    Best Answers:
    0
    Trophy Points:
    160
    #8
    No it's not
     
    Tyler Banfield, Sep 16, 2006 IP