Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 759
  • Last Modified:

Image/Hyperlink Random Script

I need a script that will randomly generate an image and the corresponding popup link. The following are three examples of hyperlinks and corresponding images. In addition I also need to run this script multiple times within the page for various product groups. Any ideas???

#1
<a href="productdetails/bathgelpure.html" TARGET="popup" ONCLICK="window.open('productdetails/bathgelpure.html', 'popup', 'width=400,height=475', 'scrollbars=yes'); return false">
<img border="0" src="siteimages/bathgelpure.gif"></a>

#2
<a href="productdetails/bathgelpure2.html" TARGET="popup" ONCLICK="window.open('productdetails/bathgelpure.html', 'popup', 'width=400,height=475', 'scrollbars=yes'); return false">
<img border="0" src="siteimages/bathgelpure2.gif"></a>

#3
<a href="productdetails/bathgelpure3.html" TARGET="popup" ONCLICK="window.open('productdetails/bathgelpure.html', 'popup', 'width=400,height=475', 'scrollbars=yes'); return false">
<img border="0" src="siteimages/bathgelpure3.gif"></a>
0
kyleareed
Asked:
kyleareed
  • 2
1 Solution
 
John KawakamiCommented:
Here's a simple javascript ad randomizer.  You define one function per ad group, with the ad keys in there.  showAdHtml builds the html for each.

<script type="text/javascript">
function showAdGroupA()
{
    names = [ 'bathgelpure', 'bathgelpure2', 'bathgelpure3' ];
    document.write( showAdHtml( names[ Math.floor(Math.random()*names.length) ] ) );
}

// this function is generic - just supply the name
function showAdHtml( name )
{
    return '<a href="productdetails/' + name +
           '.html" TARGET="popup" ONCLICK="window.open(\'productdetails/' + name +
           '.html\', \'popup\', \'width=400,height=475\', \'scrollbars=yes\'); return false"><img border="0"

src="siteimages/' + name +
           '.gif"></a>';
}

// to show the ad, do this.
showAdGroupA()
</script>
0
 
John KawakamiCommented:
The software here broke up the lines.  The following should be on one line, no breaks:

           '.html\', \'popup\', \'width=400,height=475\', \'scrollbars=yes\'); return false"><img border="0"
src="siteimages/' + name +
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now