Solved

Image/Hyperlink Random Script

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to resize a div in html 3 39
Binding a Grid in Javascript 5 45
jQuery force form POST 7 50
Can't get javascript video player button to work 8 15
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

828 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