Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I link 'random page' script with my image file?

    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?

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    Code:
    <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

  • #3
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to add 'new window' instruction?

    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>

  • #4
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    new window opens behind

    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?

  • #5
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wrong info in previous message

    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!

  • #6
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks - now working fine!

    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.

  • #7
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,065
    Thanks
    36
    Thanked 497 Times in 491 Posts

    Thumbs up

    Man, am I glad we could help you in all those posts!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •