Home  |  About  | Last |  Submit  |  Contact
AllQuests.com



Previous Question:  Linking div PNG problem  JavaScriptNext Question:  validate radio button in form  JavaScript
Question how to check image exist in javascript ( SitePoint Forums JavaScript )
Updated: 2008-09-28 02:40:24 (5)
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

Answers: how to check image exist in javascript ( SitePoint Forums JavaScript )
how to check image exist in javascript

Can't do it. JavaScript does not have access to a users file system. It's a security issue.

stymiee

how to check image exist in javascript

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).

Black Book

how to check image exist in javascript

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

arunsekarnet

how to check image exist in javascript

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

arunsekarnet

how to check image exist in javascript

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.

stymiee

Previous Question:  Linking div PNG problem  SitePoint Forums  JavaScriptNext Question:  validate radio button in form  SitePoint Forums  JavaScript

- Source: how to check image exist in javascript SitePoint Forums JavaScript
- Previous Question: Linking div PNG problem SitePoint Forums JavaScript
- Next Question: validate radio button in form SitePoint Forums JavaScript