1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

A simple Adrotator

Discussion in 'JavaScript' started by gae89, Sep 27, 2015.

  1. #1
    Hello,
    I need of a Adrotator for displayed 1 popup for 1 click.
    I have saw this script:

    <script language="JavaScript" type="text/javascript">
    ads = new Array(5);
    ads[0] = "<a href='AD URL' rel='nofollow'>" +
    "<img src='IMAGE URL' border='0' height='90px' width='468px'/></a>";
    ads[1] = "<a href='AD URL' rel='nofollow'>" +
    "<img src='IMAGE URL' border='0' height='90px' width='468px'/></a>";
    ads[2] = "<a href='AD URL' rel='nofollow'>" +
    "<img src='IMAGE URL' border='0' height='90px' width='468px'/></a>";
    ads[3] = "<a href='AD URL' rel='nofollow'>" +
    "<img src='IMAGE URL' border='0' height='90px' width='468px'/></a>";
    ads[4] = "<a href='AD URL' rel='nofollow'>" +
    "<img src='IMAGE URL' border='0' height='90px' width='468px'/></a>";
    index = Math.floor(Math.random() * ads.length);
    document.write(ads[index]);
    </script>
    HTML:

    But How I can add the ad codes like this:
    <scripttype="text/javascript">var uid ='XXXXXX';var wid ='XXXXXX';</script><scripttype="text/javascript"src="http://cdn.popcash.net/pop.js"></script>
    HTML:

     
    Solved! View solution.
    gae89, Sep 27, 2015 IP
  2. #2
    Must be a pretty old script, given that JS hasn't had a "language" attribute since 1998, the method of building the array is needlessly and pointlessly complex, it's using document.write instead of DOM manipulation, has the BORDER attribute that also has no business in HTML after 1997, lack of ALT text on the images, and has invalid height and width declarations.

    See, the HTML height and width attributes do NOT accept "px" as a metric. You want pixels you just say the number. The only accepted metric is %.

    Pixels:
    width="468"

    Percentage:
    width="50%"

    Using the STYLE attribute you really shouldn't be using:
    style="width:468px;"

    Utter and complete gibberish HTML will ignore:
    width="468px"

    See? You only say "px" if it's CSS. You NEVER say "PX" inside HTML's width and height attributes.

    Now that said, writing script from scripting is just a bad idea, as is wasting time sending code client-side that might not even get run. I would HIGHLY suggest that you instead do this server-side using something like PHP or ASP as this really has no business being controlled in JavaScript.

    In PHP that would go something like this:

    <?php
    
    $ads = ['
    	<a href="AD URL" rel="nofollow"><img
    		src="IMAGE URL"
    		alt="DESCRIBE THIS IMAGE!!!"
    		height="90" width="468"
    	></a>
    ', '
    	<script type="text/javascript">
    		var
    			uid ='XXXXXX',
    			wid ='XXXXXX';
    	</script>
    	<script type="text/javascript" src="http://cdn.popcash.net/pop.js"></script>
    '];
    
    echo $ads[rand(0, count($ads) - 1)];
    
    ?>
    Code (markup):
    * note * I'm using PHP 5.4 style arrays there.

    At least if I'm understanding what you are asking.
     
    deathshadow, Oct 5, 2015 IP
  3. AdConjure

    AdConjure Active Member

    Messages:
    57
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    65
    #3
    Hello, rather than random what you should do is integrate cookies. On first page load, pop your highest company and set cookie. Second page load see's cookie is set and serves your second highest paying pop company. This will turn non-unique page views into unique impressions on multiple ad networks. I can help you with that or I can also help you with a random output.
     
    AdConjure, Dec 16, 2015 IP
  4. AdConjure

    AdConjure Active Member

    Messages:
    57
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    65
    #4
    I keep trying to post the code you need but the post doesn't go through.. no error or anything shows, not sure what the problem is.

    Check it out on JSFiddle: https://jsfiddle.net/k068tajy/
     
    AdConjure, Dec 17, 2015 IP
  5. gae89

    gae89 Member

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    Thanks for the replies. I'm tested the method of deathshadow. :)
     
    gae89, May 10, 2016 IP