473,809 Members | 2,775 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Replace Broken Images???

Not sure if this can be done with javascript but I would like to find a way
to detect if an image is missing and replace it with a default image instead
of the dreaded RED X showing up.

So - Is Javascript the way? Or should I look elesewhere?

Thanks in Advance!
Oct 17 '05 #1
15 6226
Jake said the following on 10/17/2005 5:11 PM:
Not sure if this can be done with javascript but I would like to find a way
to detect if an image is missing and replace it with a default image instead
of the dreaded RED X showing up.
It can't be done reliably with javascript.
So - Is Javascript the way?
No.
Or should I look elesewhere?


Yes. You shoould look into dependable hosting that will make your images
available. Then you don't have the Red X problem.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 17 '05 #2
VK
> to detect if an image is missing and replace it
with a default image instead of the dreaded
RED X showing up.


<img src="some.gif" onerror="this.s rc='other.gif'; ">

Hi there...

Oct 17 '05 #3
VK said the following on 10/17/2005 7:20 PM:
to detect if an image is missing and replace it
with a default image instead of the dreaded
RED X showing up.

<img src="some.gif" onerror="this.s rc='other.gif'; ">


And if other.gif is not available?

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
Oct 17 '05 #4
VK
>>to detect if an image is missing and replace it
with a default image instead of the dreaded
RED X showing up.
<img src="some.gif" onerror="this.s rc='other.gif'; "> And if other.gif is not available?


Then "the dreaded RED X" will still make the trick (I guess it's called
"fall gracefully"?)
The server-side feed is always more reliable than js, but even that
will fail if say your user doesn't have browser, or computer, or
monitor, or nothing at all. You cannot win anyway if someone is trying
DO NOT get your site :-)

Oct 17 '05 #5

Jake <sp******@allte l.net> wrote in message news:88******** *************** ****@ALLTEL.NET ...
Not sure if this can be done with javascript but I would like to find a way
to detect if an image is missing and replace it with a default image instead
of the dreaded RED X showing up.
Presumably for images on a different server.
So - Is Javascript the way?


It's a trivial matter of using the onload event of each image to build
a table of references to succesfully-loaded images objects.
Then on document load, scan the document.images collection for a
match in the table. If none exists, substitute the .src propery of the
unmatched object with a specified file name.

<script type='text/javascript'>

var imageLog=[];

function replaceImage(su bstImg)
{
var iLen=document.i mages.length ,
logLen=imageLog .length ;

for(var i=0; i < iLen; i++)
{
for(var j=0; j<logLen && imageLog[j]!=document.imag es[i]; j++)
;
if(j==logLen)
document.images[i].src=substImg;
}
}

window.onload=f unction(){ replaceImage("s orry.jpg"); } // your substitute image here

</script>

In all <img> tags, add: onload='imageLo g[imageLog.length]=this'

Mozilla doesn't seem to support onerror, at least for images.

--
Stephen Chalmers http://makeashorterlink.com/?H3E82245A

Oct 18 '05 #6
VK
> Mozilla doesn't seem to support onerror, at least for images.

Of course it does as any other browser since 3rd NN/IE versions.
Of course the domain security applies so you cannot get onerror events
from other domains via frame/iframe tricks. But the same is true for
any other events including onload.

Oct 18 '05 #7

VK wrote:
Mozilla doesn't seem to support onerror, at least for images.


Of course it does as any other browser since 3rd NN/IE versions.
Of course the domain security applies so you cannot get onerror events
from other domains via frame/iframe tricks. But the same is true for
any other events including onload.


Further tests on Mozilla reveal that it appears to be a feature
relating to local files only, unlike I.E, Opera and NN4, which had no
difficulty getting an onerror event locally.
All including Moz got the onerror event for a fictitious file on my
webspace (called from a local file).
I haven't tested what happens between two web domains.

--
S.C.

Oct 18 '05 #8
Well, thanks for the reply but - I am the host - and I consider myself
reliable.

The problem is with clients for whom I have built database driven sites for
and a typo of the filename causes the Red X.

For example, A real estate site, the owner creates a new listing and either
types the image name wrong or fails to upload the image alltogether.
"Randy Webb" <Hi************ @aol.com> wrote in message
news:D7******** *************** *******@comcast .com...
Jake said the following on 10/17/2005 5:11 PM:
Not sure if this can be done with javascript but I would like to find a
way to detect if an image is missing and replace it with a default image
instead of the dreaded RED X showing up.


It can't be done reliably with javascript.
So - Is Javascript the way?


No.
Or should I look elesewhere?


Yes. You shoould look into dependable hosting that will make your images
available. Then you don't have the Red X problem.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

Oct 18 '05 #9
Jake said the following on 10/18/2005 1:22 AM:
Well, thanks for the reply but - I am the host - and I consider myself
reliable.

The problem is with clients for whom I have built database driven sites for
and a typo of the filename causes the Red X.

For example, A real estate site, the owner creates a new listing and either
types the image name wrong or fails to upload the image alltogether.


Then you need to educate your users/client's to test the listing after
updating it and to check the path/capitalization/spelling of the image name.

Short of that, since you are the host, you can setup a server-side
routine to scan the page for img tags, check the existence of the image,
and replace it with an image of your own - all on the server before the
page ever gets to the browser.

The server is the place to fix the problem - not the client.

Signatures can be informative.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Oct 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
1683
by: John at Free Design | last post by:
Thanks in advance for the help and let me know if this should be posted to another MSDN. I am developing a web-based application in VS.NET2003 using VB. When I insert a graphic into a project page it shows just fine in design mode. However, when I run the app in debug or directly from a browser all the graphic links in the app show they are broken. Checking the properties shows that they are pointing to the correct folder. I'm not...
5
2640
by: pembed2003 | last post by:
Hi all, I need to write a function to search and replace part of a char* passed in to the function. I came up with the following: char* search_and_replace(char* source,char search,char* replace){ char* result; size_t l = strlen(source), r = strlen(replace), i; int number_of_replaces = 0; for(i = 0; i < l; i++){ if(source == search)
7
2274
by: Jacob | last post by:
Has anybody else encountered a problem when running your asp.net applications off your localhost and having broken image links? The weird thing is, the links aren't really broken. The reference is correct. And what's weirder that than, it will only do it sporadically. I can refresh the screen and those images that were once broken are now visible but some others may now be broken. Or sometimes they all work, sometimes none. This...
12
2624
by: Charlie King | last post by:
As I understand it, the use of FIR* to replace heading tags with images in visually enabled CSS browsers is now frowned upon on the basis that some screen readers will *nor* read back text that is marked up by CSS to be invisible or hidden. So... If I want to replace headings with images (because my client wants to use his specific font for headings where possible), what's the best way to do it?
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10635
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10378
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9198
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.