Solved

Image/Hyperlink Random Script

Posted on 2006-11-29
4
750 Views
Last Modified: 2012-06-27
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
Comment
Question by:kyleareed
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
jk2001 earned 500 total points
ID: 18044486
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
 
LVL 8

Expert Comment

by:jk2001
ID: 18044489
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now