View Full Version : random image every time refresh
ModernRevolutions
06-30-2008, 01: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
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, 04:44 PM
THANKS SO MUCH!!!! it works WONDERFULLY!!!!!!!!
Your welcome. Glad it works :D
ModernRevolutions
07-02-2008, 11:17 AM
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, 11:47 AM
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, 06: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
diazfdlh
06-19-2016, 11:47 AM
I am too lazy to code it for you :p so have a look at this:
http://www.javascriptkit.com/script/cut144.shtml I have one question, the code has perfectly works but i want to know how to make 3 image per refresh, what can i see with the previous code that everytime i refresh the webpage just one image who appear, but i wanna make it 3 ore 5 image per refresh, hope you can tell me, sorry for my bad english
Beverleyh
06-20-2016, 09:36 AM
document.write is old fashioned. Instead, how about marking up all the images first with a standard HTML list format, and then randomly reveal them through the addition of a '.selected' class? This is a reusable function to demonstrate: http://jsbin.com/xowanunime/1/edit?html,css,js,output
I've prepared an actual page with some special considerations for images. Their paths are stored in "data-src" attributes and only switched to "src" once JS has selected them, meaning that only the randomly selected ones actually load (better on bandwidth and page load speed) http://fofwebdesign.co.uk/template/_testing/random-imgs.htm
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.