javascript detect image

Posted on 2005-03-16
Medium Priority
Last Modified: 2013-12-16
Hi there,

I have this situation where i am pulling in external images on a webpage from a different server to where the pages are hosted,  Now since its a dynamic site if the image is not located on the server where the URL is pointing it just shows the annoying blank frame with a red X in it.

I need to know if there is any way of using javascript or any other language for that matter for somehow detecting if the image exists;

so basically;

if image exists { show picture of image } else {
if image does not exist { show another image saying 'no image' }

is this possible?


Question by:webpolsol
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 32

Accepted Solution

Batalf earned 1000 total points
ID: 13555070
Try to put in an onerror

<img src="yourImage.gif" onError= src="errorImage.gif">
LVL 13

Expert Comment

ID: 13555421
and also

var myImage=new Image();

function myFunction(){
    alert(this.src+' not found!');


<form name="test" method="post">
   <input type="button" onClick="myFunction()" value="test me" mane="test" />

Author Comment

ID: 13556285
Works perfectly!

Many Thanks,


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question