Buying Fix my simple js random ad rotator for 2$

Discussion in 'Programming' started by sandrodz, Mar 19, 2011.

  1. #1
    This should work right? for some non obvious reason (at least to me) it doesn't.

    I need fast fix, if I figure it out myself in few hours I will not pay.
     
    sandrodz, Mar 19, 2011 IP
  2. sandrodz

    sandrodz Peon

    Messages:
    1,482
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    <script language="JavaScript">
    <!--
    // here we generate random number 0 or 1
    var i = Math.floor(2*Math.random())
    // see if randomness is really working.
    //document.write([i]);
    // my if statement, depending on random number, we display 1 ad or the other.
    if (i == 1)
    {
    // Test ad 300^250 #1 Current one, blend in style, no borders
    document.write('<script type=\"text/javascript\"><!--\n\
    /* Footer Related */
    google_ad_width = 300;\n\
    google_ad_height = 250;\n\
    //-->
    <\/script>\n\
    <script type=\"text/javascript\"\n\
    src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">\n\
    <\/script>\n\');
    }
    else
    {
    // Test ad 300^250 #2 Stand out version, border and also colors
    document.write('<script type=\"text/javascript\"><!--\n\
    /* Footer - Related Test (Stand out) */
    google_ad_width = 300;\n\
    google_ad_height = 250;\n\
    //-->
    <\/script>\n\
    <script type=\"text/javascript\"\n\
    src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">\n\
    <\/script>\n\');
    }
    //-->
    </script>
    Code (markup):
     
    sandrodz, Mar 19, 2011 IP
  3. deutsched

    deutsched Active Member

    Messages:
    159
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    85
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    Try that:

    <script language="JavaScript">
    <!--
    // here we generate random number 0 or 1
    var i = Math.floor(2*Math.random())
    // see if randomness is really working.
    //document.write([i]);
    // my if statement, depending on random number, we display 1 ad or the other.
    if (i == 1)
    {
    // Test ad 300^250 #1 Current one, blend in style, no borders
    document.write('<script type=\"text/javascript\"><!--\n\
    google_ad_width = 300;\n\
    google_ad_height = 250;\n\
    <\/script>\n\
    <script type=\"text/javascript\"\n\
    src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">\n\
    <\/script>\n');
    }
    else
    {
    // Test ad 300^250 #2 Stand out version, border and also colors
    document.write('<script type=\"text/javascript\"><!--\n\
    google_ad_width = 300;\n\
    google_ad_height = 250;\n\
    <\/script>\n\
    <script type=\"text/javascript\"\n\
    src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">\n\
    <\/script>\n');
    }
    //-->
    </script>
    Code (markup):
    Haven't tested it though..
     
    deutsched, Mar 19, 2011 IP
  4. sandrodz

    sandrodz Peon

    Messages:
    1,482
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    it doesnt work. you should be able to just open it on ur comp and see it working right?
     
    sandrodz, Mar 19, 2011 IP
  5. deutsched

    deutsched Active Member

    Messages:
    159
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    85
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #5
    No, Google AdSense won't display any ads if I just put it in a blank file
    I'll just insert it into one of my sites and test it
     
    deutsched, Mar 19, 2011 IP
  6. sandrodz

    sandrodz Peon

    Messages:
    1,482
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #6
    try it, I just checked with plain adsense code and it worked. the script i've will not work cause I stripped out pub id and slot id.
     
    sandrodz, Mar 19, 2011 IP
  7. deutsched

    deutsched Active Member

    Messages:
    159
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    85
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #7
    Here's the code once again

    I tested it on http://www.boghdady.com/about.php , right below the main content text
    It displays the ad box, but the box is empty
    So my guess that there is something wrong with the adsense ad code itself, but the script is working fine..

    <script language="JavaScript">
    
    // here we generate random number 0 or 1
    var i = Math.floor(2*Math.random())
    // see if randomness is really working.
    //document.write([i]);
    // my if statement, depending on random number, we display 1 ad or the other.
    if (i == 1)
    {
    // Test ad 300^250 #1 Current one, blend in style, no borders
    document.write('<script type=\"text/javascript\">\n\
    google_ad_width = 300;\n\
    google_ad_height = 250;\n\
    <\/script>\n\
    <script type=\"text/javascript\"\n\
    src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">\n\
    <\/script>\n');
    }
    else
    {
    // Test ad 300^250 #2 Stand out version, border and also colors
    document.write('<script type=\"text/javascript\">\n\
    google_ad_width = 300;\n\
    google_ad_height = 250;\n\
    <\/script>\n\
    <script type=\"text/javascript\"\n\
    src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">\n\
    <\/script>\n');
    }
    </script>
    Code (markup):
     
    deutsched, Mar 19, 2011 IP
  8. sandrodz

    sandrodz Peon

    Messages:
    1,482
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #8
    hm, thats my problem... I don't know to properly comment out parenthesis?

    I know that script works correctly, I tested it with //document.write();

    for some reason my adsense code inside js doesn't work properly.
     
    sandrodz, Mar 19, 2011 IP
  9. deutsched

    deutsched Active Member

    Messages:
    159
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    85
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #9
    Your AdSense ad code looks really different than mine
    I'm not sure why :S
     
    deutsched, Mar 19, 2011 IP
  10. sandrodz

    sandrodz Peon

    Messages:
    1,482
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #10
    I'm still having the problem, ads don't display :(

    I'm gonna try document write each line.
     
    sandrodz, Mar 20, 2011 IP