...

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



fearless3955
09-11-2008, 10: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, 12:00 PM
<img src = "yourImage.gif" onclick = "go()">

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

</script>


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

fearless3955
09-12-2008, 10: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:
<script>
function random_all(){
var myrandom=Math.round(Math.random()*(document.links.length-1))
window.location=document.links[myrandom].href
}</script>

fearless3955
09-12-2008, 11:11 AM
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?

fearless3955
09-12-2008, 11:20 AM
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!

fearless3955
09-15-2008, 05: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.

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum