SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Using RegEx to look for images in a particular URL location...

    The following code sets the variable "url" to be initialized to a single image file location relative to where this script runs and from there, simply fires off a function if it exists or doesn't:

    Code:
    var url = 'images/slideshow/fall1.png';
    alert(url);
    $.ajax({
        url:url,
        type:'HEAD',
        error:
            function(){
                alert('No image found.');
            },
        success:
            function(){
                alert('Image found.');
            }
    });
    What I would like to do is have this entire script work against something like "images/slideshow/*.png" where the asterisk acts as a wildcard to synthesize directory traversal. Obviously, JavaScript / jQuery can't do server-side ops, but could I use a RegEx somehow to fulfill this?

  2. #2
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Never mind everyone... I found a solution:

    Code:
    var url = 'images/slideshow/';
    $.ajax({
      url:url,
      success: function(data){
         $(data).find("a:contains(.png)").each(function(){
            aImages.push(url+$(this).attr("href"));
         });
      }
    });


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
  •