SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Resistance is Futile webgodjj's Avatar
    Join Date
    Nov 2002
    Location
    Madison, WI USA
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    slideshow and dynamic array

    Ok... I have seen many slideshow ideas out there. However, most require you to know the names of the images, then put them into an array.

    I would like to constantly update these images.. so it would be ideal if I could have the script scan a directory of images and put them into an array... I know PHP can do this... can javascript? Here is one of many scripts I have found (I don't really need links...):

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    
    /*
    Script by FPMC at http://jsarchive.8m.com
    Submitted to JavaScript Kit (http://javascriptkit.com)
    For this and 400+ free scripts, visit http://javascriptkit.com
    */
    
    //set image paths
    src = ["image1.gif", "image2.gif", "image3.gif", "image4.gif"]
    
    
    //set corresponding urls
    url = ["http://freewarejava.com", "http://javascriptkit.com", "http://dynamicdrive.com", "http://www.geocities.com"]
    
    //set duration for each image
    duration = 4;
    
    //Please do not edit below
    ads=[]; ct=0;
    function switchAd() {
    var n=(ct+1)%src.length;
    if (ads[n] && (ads[n].complete || ads[n].complete==null)) {
    document["Ad_Image"].src = ads[ct=n].src;
    }
    ads[n=(ct+1)%src.length] = new Image;
    ads[n].src = src[n];
    setTimeout("switchAd()",duration*1000);
    }
    function doLink(){
    location.href = url[ct];
    } onload = function(){
    if (document.images)
    switchAd();
    }
    //-->
    </SCRIPT>
    
    <A HREF="javascript:doLink();" onMouseOver="status=url[ct];return true;" 
    onMouseOut="status=''">
    <IMG NAME="Ad_Image" SRC="image1.gif" BORDER=0>
    </A>
    
    <p align="center"><font face="arial" size="-2">This free script provided by <a href="http://javascriptkit.com">JavaScript Kit</a></font></p>

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I Did something like this when I first started learning, However I used php to populate an array to disply the images. However there are a couple ways I can think of although not very effective... As I would suggest using a server side language if you can...



    Code:
        <script type="text/javascript">
        <!--
    
          function init()
          {
    
            try
            {
              var i     = 0;
              var j     = 0;
    
              var url   = "http://www.sitepointforums.com/images/top_logo_sitepoint.gif";
              var admin = "AJohnstone2000@Hotmail.Com";
    
              window.status = 'examining directory...';
    
              var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
              xmlhttp.open("GET", url, false);
    
              xmlhttp.onreadystatechange = function()
                                           {
                                             if (xmlhttp.readyState    == 4  )
                                             {
                                               if (xmlhttp.status      == 200)
                                               {
                                                 window.status = 'URL resolved. reporting error. for further infomation please contact <a href="mailto://' + admin + '">admin</a>';
                                                 /* server header responses */
                                                 alert(xmlhttp.getAllResponseHeaders());
    
                                                 alert(  xmlhttp.status      );
                                                 alert(  xmlhttp.statusText  );
                                                 alert(  xmlhttp.responseText);
    
                                               }
                                               else if (xmlhttp.status == 404)
                                               {
                                                 window.status = 'URL could not be resolved. Please contact <a href="mailto://' + admin + '">admin';
                                               }
                                               else
                                               {
                                                 window.status = 'Status is ' + xmlhttp.status;
                                               }
                                             }
                                           }
              xmlhttp.send(null);
            }
            catch(e)
            {
              alert('error occurred \n' + e.description);
            }
          }
    
        -->
        </script>
    basically put this function into a loop on your directry and label all images like "1.jpg", but remember to set all variables after the each loop to null and disable all cacheing... In the above example use the xmlhttp.status to check for a 404 or a 200 to check whether the file exists.

    alternatively you could return the maximum image number in the header from your webserver.

    or

    Heres another method... http://www.webreference.com/js/column98/index.html

    and another...

    http://www.ashleyit.com/rs/main.htm

    As I said your probably best off with using a server side language...


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
  •