Solved

Image/Hyperlink Random Script

Posted on 2006-11-29
4
755 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…
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…

734 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