Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

random image on page load or refresh

Featured Replies

Hi, I have a page (http://www.abimagery.co.uk/abimagery-galleries.html) where i want to have random images displayed for each different gallery.

 

I've seen scripts that will do this for a single image location on the page but can't find anything that would solve my problem.

 

Hope someone can help.

 

Cheers

 

Tony

I think this is the code you want buddy...I use this myself on my website.

 

<script language="JavaScript">

<!--

/*

Random Image Link Script

By Website Abstraction (http://www.wsabstract.com)

and Java-scripts.net (http://www.java-scripts.net)

*/

 

function random_imglink(){

var myimages=new Array()

//specify random images below. You can have as many as you wish

myimages[1]="YOURIMAGE1.GIF"

myimages[2]="YOURIMAGE2.GIF"

myimages[3]="YOURIMAGE3.GIF"

 

//specify corresponding links below

var imagelinks=new Array()

imagelinks[1]="LINK1"

imagelinks[2]="LINK2"

imagelinks[3]="LINK3"

 

var ry=Math.floor(Math.random()*myimages.length)

 

if (ry==0)

ry=1

document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')

}

 

random_imglink()

//-->

</script>

Or you could use php. I'll see if I can dig up my old random image script.

  • Author

brilliant thanks for that.

 

i'm presuming i can put this script at whichever location i want the random image to occur or if it has to go in the </head> it won't do what i need.

No it doesn't have to go into the head I shouldn't think so. Give it a try were you want it and see how it goes. :)

  • Author

Sorry, i had to dash away yesterday . . .

 

brilliant i will give it a try today and let you know how i get on

 

cheers

 

Tony

  • Author

Hi Finnan3,

 

Script works a treat.

 

Really appreciate your help.

 

Cheers

 

Tony

Hi Finnan3,

 

Script works a treat.

 

Really appreciate your help.

 

Cheers

 

Tony

 

No worries..happy to help. :drinks:

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.