...

View Full Version : Random Link



oldmanschild
11-07-2004, 01:36 AM
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 (http://rippingdeath.com/renmovie.gif)

kwhubby
11-07-2004, 09:18 AM
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()">

Willy Duitt
11-07-2004, 06:36 PM
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....



<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

oldmanschild
11-08-2004, 01:02 AM
But Willy what do i put where it says this?

joh6nn
11-08-2004, 01:44 AM
nothing; it's supposed to say "this". don't change it.

Willy Duitt
11-08-2004, 02:40 AM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum