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 6 of 6

Thread: Random Link

  1. #1
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Random Link

    Please help me. I want to make a new random link. But i only know how to make them using a button. I made a very cute picture of my new chinchilla, Ren, and would like to have him be a random link. So will you please help me make a random link using a picture? By the way, the picture is athere

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Location
    Carmel California
    Posts
    471
    Thanks
    0
    Thanked 1 Time in 1 Post
    Well you can have a link do a function as pseudo url code. <a href="javascript:function()">blah</a> just as you might do <input type="button" onclick="function()">
    Kris Hubby
    kwhubby site

  • #3
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could try this...
    Add the script block to the HEAD and add the onload event handler to the image to convert the image to an anchor onload... Those with javascript disabled will only see the image... Those with javascript enabled will see the pointer and be able to follow the link....

    Code:
    <script type="text/javascript">
     <!--//
      function link(image){
       var randomLinks = new Array(); 
           randomLinks[0] = 'http://site0.html' 
           randomLinks[1] = 'http://site1.html'
           randomLinks[2] = 'http://site2.html'
           randomLinks[3] = 'http://site3.html'
           randomLinks[4] = 'http://site4.html'
           randomLinks[5] = 'http://site5.html'
           randomLinks[6] = 'http://site6.html'
           randomLinks[7] = 'http://site7.html'
           randomLinks[8] = 'http://site8.html'
           randomLinks[9] = 'http://site9.html'
    
       var randomLink = randomLinks[Math.round(Math.random()*(randomLinks.length-1))];
           image.onclick = function(){ location.href = randomLink }
           image.onmouseover = function(){ window.status = randomLink }
           image.onmouseout = function(){ window.status = '' }
           image.style.cursor = 'pointer';
      }
     //-->
    </script>
    </head>
    
    <body>
    <img src="renmovie.gif" onload="link(this)">
    .....Willy

  • #4
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    But Willy what do i put where it says this?

  • #5
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    nothing; it's supposed to say "this". don't change it.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #6
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this in the context it is being used is a direct reference to the image object it is associated with... (as Joh6nn stated, do not change this)

    I wrote that to be as simple to implement as possible...
    All you need to do is add your links to the randomLinks array and add the onload event handler to the image...

    .....Willy


  •  

    Posting Permissions

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