Solved

Image/Hyperlink Random Script

Posted on 2006-11-29
4
754 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
John Kawakami 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:John Kawakami
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

737 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