PDA

View Full Version : random image every time refresh


ModernRevolutions
06-30-2008, 02:51 PM
i need a very simple code to make it so my affilates button shuffle through every time you refresh or go to another part of the site.


here is my site. modernrevolutions.net and where it says affiliates i want it to have 1 button and then refresh and then pick another one at random. however i still have to be able to make the pics links to the site of course and i want it so when the pic changes the URL to the site stays with the image lol. it would be wonderful if someone gave me the code :) thanks

Jas
06-30-2008, 04:32 PM
I am too lazy to code it for you :p so have a look at this:

http://www.javascriptkit.com/script/cut144.shtml

ModernRevolutions
06-30-2008, 05:44 PM
THANKS SO MUCH!!!! it works WONDERFULLY!!!!!!!!

Jas
07-01-2008, 01:20 AM
Your welcome. Glad it works :D

ModernRevolutions
07-02-2008, 12:17 PM
ok im using the code and it working perfectly, however i want to make it so when someone clicks on the affiliate button it opens in a new window/tab. and i try adding target="new" at after the URL and it didnt work. the image just disappeared

codeexploiter
07-02-2008, 12:47 PM
You need to make some changes in the below mentioned code. Highlighted the changes you need to make.
document.write('<a href='+'"'+imagelinks[ry]+'"'+' ><img src="'+myimages[ry]+'" border=0 id="image"></a>')

Insert the following code in to the script element of your page.

function openWin(){
var w = window.open("","","height=400,width=500");
w.document.write ("<html>\n<head>\n<title>Popup Document</title>\n</head>\n<body>\n");
w.document.write ("<img src='" + document.getElementById('image').src + "' border='0'>");
w.document.write ("\n</body\n</html>");
w.document.close();
}


After that in onclick event of the button you've mentioned invoke openWin function. You'll be able to open a new window and the image will be in it.

Hope this helps.

magicyte
07-07-2008, 07:25 PM
One way to code it yourself and not STEAL would be to use the Math.random() function along with the Math.round() function. Note that this is JavaScript.

-maigcyte