I have the following page header in my page.tpl.php file:

I'd like to add a different image to this header for each page created. I thought the best way would be to use javascript to do a random load. I can apply a static image to the page header using

But is it possible to use this type of markup in a javascript file for a loading a random image? Or am I going about this the wrong way?
Any help would be appreciated. Thanks.

P.S. I removed the opening "<" for the img file just so it will show up in this post. It's included in my actual file.

Comments

Radiant Freedom’s picture

Do you know how many images you'll have to work with? If not, you'll need to first run a counter function to count how many images are in your table for your random image pool. Once you know that, you can use javascript to generate a random number (n) between 0 and (# of images -1), then pull the "n"th image from the table. I'd recommend you don't go too crazy with the number of images in your pool, as the bigger it gets the slower your site will become.

brutusmc’s picture

Thanks for your reply. Actually, I found a good solution here:

https://www.drupal.org/node/29522