View Full Version : How do I link 'random page' script with my image file?

09-11-2008, 11:40 AM
I've found some workable scripts to send visitors to a random page within my site but there's never an explanation how to assign that script to an existing image, instead of JS specifically creating an ugly button itself. (I'm using Dreamweaver on a Mac). Can anyone point me in the right direction with some VERY simple instructions?

Philip M
09-11-2008, 01:00 PM
<img src = "yourImage.gif" onclick = "go()">

<script type = "text/javascript">
function go() {
// redirect to random page


"This is the worst disaster in California since I was elected." --California Governor Pat Brown, discussing a local flood

09-12-2008, 11:40 AM
Many thanks. That works, though I can't figure how/where to get this to open the random page in a NEW window. Do I amend my 'random open' script as adding the usual target="_blank" instruction to the html doesn't seem to work in this instance? This is the script I'm using:
function random_all(){
var myrandom=Math.round(Math.random()*(document.links.length-1))

09-12-2008, 12:11 PM
Actually - I take that back... but strangely the new window opens behind instead of in front. This is the code Dreamweaver inserts:
a href="#" target="_blank"
Have I just got things in the wrong order or do I need to specify 'in front' somehow?

09-12-2008, 12:20 PM
Sorry, again, ... I now see that what's actually happening is that the instruction does open a new window in front but it re-opens the same page in that new window (presumably because of the a href="#" instruction), while changing the original window (behind) to my random page! So it's back to my original question today... if anyone has the patience!

09-15-2008, 06:07 PM
I've now got this working properly thanks to this site. I'm not sure how I did it, or even if it works as intended on anything other than a Mac, but if anyone needs to see/use the working code:
http://www.valrutt.com and just roll over the PC screen image where this whacky little function is located.

09-15-2008, 10:40 PM
:rolleyes: Man, am I glad we could help you in all those posts! :D