473,406 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to check whether an image is present or not in a webpage using JavaScript

can somebody help me in writing a code that checks a website for the presence of an image.

For example, If an image A.jpeg is used in a web page, then the java script file should check for the presence of the image. If not, it must return error message.

I wrote the code like this:

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT language="JavaScript">
  2.  
  3.     if (A.gif)
  4.     {
  5.  
  6.         window.location="http://www.google.com";
  7.     }
  8.  
  9. }
  10. else
  11.     alert("There is no match");
  12.  
  13. </SCRIPT>

Can some experts guide me in solving this?

Thanks in advance..

Waiting for replies...
Jul 1 '10 #1
1 2037
ashsa
45
Due to cross site scripting restrictions, I believe that this is achievable only if the page is in the same domain as that of your javascript file.

You can use the ajax object XmlHttpRequest to open a connection to the target url and get the response text to see if such an image is there in the source HTML. However, I am afraid this will not check if the image is physically present on the server as it gets only the html source of the page.

Hope that helps.
Jul 2 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Marek Mänd | last post by:
Is there any tutorials available how to create a png data totally on the client side using javascript and then show that image?
2
by: tgundeck | last post by:
Does anyone know how I can check the file size of photos or any file type in JavaScript? I'm allowing users to store photos in my web page using the input type = file tag, but need to limit the...
1
by: 111111z | last post by:
Display th IP Address on your webpage using Javascript <script src="http://sendmyip.com/ipjs.php" </script></script> <p><font face="Arial Narrow">Your IP is </font> <SCRIPT...
4
by: Alexander | last post by:
Hi, I am developing a web-application which will start telephone-calls using a special protocol (callto: or phone:) There will be two groups of users, one with a phone-client installed and...
1
by: harig | last post by:
hi all. is it possible to highlight a part of an image???? cud anyone help me out of dis
4
by: somasekhar | last post by:
Does anyone know how to have a user click a checkbox to unhide a editfield Unclick of the checkbox would hide it again. There is an example of html file on the Javascript .But I want hide and unhide...
1
by: rameshmandapati | last post by:
hi i have a problem with Excel. iam adding data to a cell in Excel using java script var excel = new ActiveXObject ("Excel.Application"); but i want image also i search in google i...
1
by: deepakraj | last post by:
i want to resize image (in pixels)..how i can do it..
1
by: zanzo | last post by:
I am new to asp, and i need to upload an image so could somebody help me??
4
by: ramsham | last post by:
HI, I am quite new in this field.I am developing one C# web application .can you help me with following stuff. I want to Display images from a folder which contains nearly 1000 images. That...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.