/    Sign up×
Community /Pin to ProfileBookmark

Random Image with onclick popup link

Hi
I’m setting up a random script to select from 5 different images, and they each have their own url they will link to when clicked. This works fine. The problem I’m having is when clicking on these random images when they load, having the url they link to be in a popup sized window. I know about onclick events, etc, but tieing all these things together is what’s screwing me up. Any help would be appreciated. Thanks.
Here’s my code so far.

<script language=”JavaScript”>
<!– Hide from old browsers

var imagenumber = 5 ;
var randomnumber = Math.random() ;
var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;
images = new Array
images[1] = “http://10.1.1.168/Hunter/consumerSite/media/home/teasers/airmax.jpg
images[2] = “http://10.1.1.168/Hunter/consumerSite/media/home/teasers/ezblade.jpg
images[3] = “http://10.1.1.168/Hunter/consumerSite/media/home/teasers/esav.jpg
images[4] = “http://10.1.1.168/Hunter/consumerSite/media/home/teasers/wobble.jpg
images[5] = “http://10.1.1.168/Hunter/consumerSite/media/home/teasers/ezglass.jpg
var image = images[rand1]

links = new Array
links[1] = “http://10.1.1.168/Hunter/consumerSite/features/airmax.php
links[2] = “http://10.1.1.168/Hunter/consumerSite/features/ez-blades.php
links[3] = “http://10.1.1.168/Hunter/consumerSite/features/energysav.php
links[4] = “http://10.1.1.168/Hunter/consumerSite/features/wobblefree.php
links[5] = “http://10.1.1.168/Hunter/consumerSite/features/ez-glass.php
var link = links[rand1]// — End Hiding Here –>

</script>

<script language=”JavaScript”>
<!– Hide this script from old browsers –>
document.write(‘<A HREF=”‘ + link + ‘”><IMG SRC=”‘ + image + ‘” border=”0″></a>’)
<!– End Hiding Here –>
</script>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@NevermoreMar 11.2003 — <script language="JavaScript">

<!-- Hide from old browsers

var imagenumber = 5 ;

var randomnumber = Math.random() ;

var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;

images = new Array

images[1] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/airmax.jpg"

images[2] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/ezblade.jpg"

images[3] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/esav.jpg"

images[4] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/wobble.jpg"

images[5] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/ezglass.jpg"

var image = images[rand1]

links = new Array

links[1] = "http://10.1.1.168/Hunter/consumerSite/features/airmax.php"

links[2] = "http://10.1.1.168/Hunter/consumerSite/features/ez-blades.php"

links[3] = "http://10.1.1.168/Hunter/consumerSite/features/energysav.php"

links[4] = "http://10.1.1.168/Hunter/consumerSite/features/wobblefree.php"

links[5] = "http://10.1.1.168/Hunter/consumerSite/features/ez-glass.php"

var link = links[rand1]// -- End Hiding Here -->

</script>


<script language="JavaScript">

<!-- Hide this script from old browsers -->

newwindow=window.open("","");

newwindow.write('<A HREF="' + link + '"><IMG SRC="' + image + '" border="0"></a>')

<!-- End Hiding Here -->

</script>
Copy linkTweet thisAlerts:
@chadman78authorMar 11.2003 — Thanks for the help, but it still doesn't seem to work right.

the random image needs to load in the same window, not a popup. When the random image loads thought, once you click on it, then that url will open up in a new window. I don't know if that makes sense or not.

anyway, thanks for your help.
Copy linkTweet thisAlerts:
@joeys1Mar 13.2003 — Not a problem, really. What you would do is throw this part of the script into a webpage:

<script language="JavaScript">

<!-- Hide from old browsers

var imagenumber = 5 ;

var randomnumber = Math.random() ;

var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;

images = new Array

images[1] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/airmax.jpg"

images[2] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/ezblade.jpg"

images[3] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/esav.jpg"

images[4] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/wobble.jpg"

images[5] = "http://10.1.1.168/Hunter/consumerSite/media/home/teasers/ezglass.jpg"

var image = images[rand1]

links = new Array

links[1] = "http://10.1.1.168/Hunter/consumerSite/features/airmax.php"

links[2] = "http://10.1.1.168/Hunter/consumerSite/features/ez-blades.php"

links[3] = "http://10.1.1.168/Hunter/consumerSite/features/energysav.php"

links[4] = "http://10.1.1.168/Hunter/consumerSite/features/wobblefree.php"

links[5] = "http://10.1.1.168/Hunter/consumerSite/features/ez-glass.php"

var link = links[rand1]// -- End Hiding Here -->

</script>

Then, at the appropriate part of the same page, you'd put the other script in, with a bit of modification:


<script language="JavaScript">

<!-- Hide this script from old browsers -->

document.write('<A HREF="' + link + '" TARGET="_blank"><IMG SRC="' + image + '" border="0"></a>')

<!-- End Hiding Here -->

</script>

the target part of the <a> tag will open a new window when the link is clicked.
×

Success!

Help @chadman78 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.10,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...