SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Aug 2004
    Location
    chennai
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post how to check image exist in javascript

    I've been on the hunt for a simple little function that will detect whether or not an image file exists when a user selects the file from their hard drive or types in the location. Just need it to alert that there is no such file if it truly does not exist. IE only

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,449
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Can't do it. JavaScript does not have access to a users file system. It's a security issue.

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    Durham
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it run locally or from the web? If it's locally, then you could have a look at using JScript and the filesystemobject (since this is IE only). There's warnings and stuff to let the user know what you are doing though (for obvious reasons).

  4. #4
    SitePoint Member
    Join Date
    Aug 2004
    Location
    chennai
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have got a javascript to check if the image exist, but i could not able to implement it,


    var img = new Image()
    img.onload = function(){imageExists(true)}
    img.onerror = function(){imageExists(false)}
    img.src = input_src_string
    function imageExists(exists)
    {
    if(exists)
    //do this
    else
    // do that
    }

    plz, explain me how use this code

  5. #5
    SitePoint Member
    Join Date
    Aug 2004
    Location
    chennai
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    i have got a javascript to check if the image exist, but i could not able to implement it,


    var img = new Image()
    img.onload = function(){imageExists(true)}
    img.onerror = function(){imageExists(false)}
    img.src = input_src_string
    function imageExists(exists)
    {
    if(exists)
    //do this
    else
    // do that
    }

    plz, explain me how use this code

  6. #6
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,449
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    If you're passing it a string with the location of the image it won't work. Javascript can't read to the file system.


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
  •