title: Get Image Source URLs from a Different Page Using JS
body: <p>Everyone:</p>
  
  <p>I'm trying to grab the source URLs of images from one page and use them in some JavaScript in another page. I know how to pull in images using JQuery .load(). However, rather than load all the images and display them on the page, I want to just grab the source URLs so I can use them in a JS array.</p>
  
  <p>Page 1 is just a page with images:</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;img id="image0" src="image0.jpg" /&gt;
      &lt;img id="image1" src="image1.jpg" /&gt;
      &lt;img id="image2" src="image2.jpg" /&gt;
      &lt;img id="image3" src="image3.jpg" /&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Page 2 contains my JS. (Please note that the end goal is to load images into an array, randomize them, and using cookies, show a new image on page load every 10 seconds. All this is working. However, rather than hard code the image paths into my javascript as shown below, I'd prefer to take the paths from Page 1 based on their IDs. This way, the images won't always need to be titled "image1.jpg," etc.)</p>
  
  <pre><code>&lt;script type = "text/javascript"&gt;
          var days = 730;
          var rotator = new Object();
          var currentTime = new Date();
          var currentMilli = currentTime.getTime();
          var images = [], index = 0;
          images[0] = "image0.jpg";
          images[1] = "image1.jpg";
          images[2] = "image2.jpg";
          images[3] = "image3.jpg";
          rotator.getCookie = function(Name) { 
              var re = new RegExp(Name+"=[^;]+", "i"); 
              if (document.cookie.match(re)) 
                  return document.cookie.match(re)[0].split("=")[1];
                  return''; 
          }
          rotator.setCookie = function(name, value, days) { 
              var expireDate = new Date();
              var expstring = expireDate.setDate(expireDate.getDate()+parseInt(days));
              document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
          }
          rotator.randomize = function() {
              index = Math.floor(Math.random() * images.length);
              randomImageSrc = images[index];
          }
          rotator.check = function() {
              if (rotator.getCookie("randomImage") == "") {
                  rotator.randomize();
                  document.write("&lt;img src=" + randomImageSrc + "&gt;");
                  rotator.setCookie("randomImage", randomImageSrc, days);
                  rotator.setCookie("timeClock", currentMilli, days);
              }
              else {
                  var writtenTime = parseInt(rotator.getCookie("timeClock"),10);
                  if ( currentMilli &gt; writtenTime + 10000 ) {
                      rotator.randomize();
                      var writtenImage = rotator.getCookie("randomImage")
                      while ( randomImageSrc == writtenImage ) {
                          rotator.randomize();
                      }
                      document.write("&lt;img src=" + randomImageSrc + "&gt;");
                      rotator.setCookie("randomImage", randomImageSrc, days);
                      rotator.setCookie("timeClock", currentMilli, days);
                  }
                  else {
                      var writtenImage = rotator.getCookie("randomImage") 
                      document.write("&lt;img src=" + writtenImage + "&gt;");
                  }
              }
          }
          rotator.check()
      &lt;/script&gt;
  </code></pre>
  
  <p>Can anyone point me in the right direction? My hunch is to use JQuery .get(), but I've been unsuccessful so far.</p>
  
  <p>Please let me know if I can clarify!</p>