Results 1 to 9 of 9

Thread: random image every time refresh

  1. #1
    Join Date
    Aug 2006
    Posts
    235
    Thanks
    30
    Thanked 2 Times in 2 Posts

    Exclamation random image every time refresh

    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

  2. #2
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    I am too lazy to code it for you so have a look at this:

    http://www.javascriptkit.com/script/cut144.shtml
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  3. The Following User Says Thank You to Jas For This Useful Post:

    ModernRevolutions (06-30-2008)

  4. #3
    Join Date
    Aug 2006
    Posts
    235
    Thanks
    30
    Thanked 2 Times in 2 Posts

    Default

    THANKS SO MUCH!!!! it works WONDERFULLY!!!!!!!!

  5. #4
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    Your welcome. Glad it works
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  6. #5
    Join Date
    Aug 2006
    Posts
    235
    Thanks
    30
    Thanked 2 Times in 2 Posts

    Default

    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

  7. #6
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    You need to make some changes in the below mentioned code. Highlighted the changes you need to make.
    Code:
    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.
    Code:
    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.

  8. #7
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    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

  9. #8
    Join Date
    Jun 2016
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 3-5 image per refresh

    Quote Originally Posted by Jas View Post
    I am too lazy to code it for you 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

  10. #9
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    2,968
    Thanks
    25
    Thanked 578 Times in 558 Posts
    Blog Entries
    33

    Default

    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/_...andom-imgs.htm
    Last edited by Beverleyh; 06-20-2016 at 03:06 PM. Reason: 2nd demo added with img/page load considerations
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  11. The Following User Says Thank You to Beverleyh For This Useful Post:

    Ripsaw (06-26-2016)

Bookmarks

Posting Permissions

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