Random picture

  • 0
  • 1
  • Question
  • Updated 5 years ago
  • Answered
Archived and Closed

This conversation is no longer open for comments or replies and is no longer visible to community members. The community moderator provided the following reason for archiving: We have archived this topic as it has either reached a resolution or has become inactive.  If you believe this topic should not have been archived, please let us know, and we would be happy to review it.  You may continue to access this topic as needed fo

Hello,

I have javascript code to randomly change the main image on every visit for the index page.  However, I need to access the index's HTML source to enter the line of code for the specific area to hold the image.  How can I do this?  Or does HomeStead have a prebuilt function similar?

Photo of John8481

John8481

  • 280 Points 250 badge 2x thumb

Posted 5 years ago

  • 0
  • 1
Photo of Drew N

Drew N, Alum

  • 262,676 Points 100k badge 2x thumb
Hi John8481,

I am not exactly sure what script you are using, but typically, it would be added to an HTML box in Sitebuilder, then you can drag that box around on the page to place it. Here's how to add HTML

Thanks

Drew
Photo of John8481

John8481

  • 280 Points 250 badge 2x thumb

This is the script I have in an HTML box would go after the HTML body:

<script language="JavaScript" type="text/javascript">
<!-- // JavaScript to interpolate random images into a page.

var imgNum = 6; // Number of alternative images
var imgAlt = new  array(imgNum);

// Array to hold filenames
imgAlt[0] = "http://www.legionofmarymichigan.org/imgArr/1.png";
imgAlt[1] = "
http://www.legionofmarymichigan.org/imgArr/2.png";
imgAlt[2] = "
http://www.legionofmarymichigan.org/imgArr/3.png";
imgAlt[3] = "
http://www.legionofmarymichigan.org/imgArr/4.png";
imgAlt[4] = "
http://www.legionofmarymichigan.org/imgArr/5.png";
imgAlt[5] = "
http://www.legionofmarymichigan.org/imgArr/6.png";

function pickRandom(range)
{
   if (Math.random) return Math.round(Math.random() * (range-1));

   else
   {
      var now = new Date();
      return (now.getTime() / 1000) % range;
   }
}

// Write out an IMG tag, using a randomly-chosen image name.
var choice = pickRandom(imgNum);

// --> </script>


Then I have this script to show the image:

<SCRIPT
LANGUAGE="JavaScript">document.writeln('<TD'+'><IMG SRC="'+imgAlt[choice]+'"
HEIGHT=425 WIDTH=785 BORDER=0 ><'+'/TD>');</SCRIPT>


Photo of Drew N

Drew N, Alum

  • 262,646 Points 100k badge 2x thumb
If the script needs to be in the body, then an HTML box is how to do it.  They are placed inside the body tags.  There is also a java script section in the Page settings > Advanced, but that wil be onload and onunload.

I have not added java to an HTML box before, but that will be the way you will have to try, as there is no access to the source code of the page.

Drew

This conversation is no longer open for comments or replies.