Connecting Tech Pros Worldwide Help | Site Map

Alternative Image

  #1  
Old July 23rd, 2005, 08:52 PM
joe
Guest
 
Posts: n/a
Hi. Is there a way with Javascript to use a generic image if the one I want
is not found?
I'd appreciate if someone can post a code sample, or poit me to one. Thanks
in advance.


  #2  
Old July 23rd, 2005, 08:52 PM
RobB
Guest
 
Posts: n/a

re: Alternative Image


joe wrote:[color=blue]
> Hi. Is there a way with Javascript to use a generic image if the one[/color]
I want[color=blue]
> is not found?
> I'd appreciate if someone can post a code sample, or poit me to one.[/color]
Thanks[color=blue]
> in advance.[/color]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">

img {display: block;}

</style>
</head>
<body>
<img
src="http://www.google.com/intl/en/images/logo.gif"
onerror="this.src='http://www.sonofsofaman.com/images/photo-not-available-180x240.gif'">
<img
src="http://www.google.com/intl/en/images/logo.giff"
onerror="this.src='http://www.sonofsofaman.com/images/photo-not-available-180x240.gif'">
</body>
</html>

Could do this more systematically...

  #3  
Old July 23rd, 2005, 08:52 PM
joe
Guest
 
Posts: n/a

re: Alternative Image


Ok. I think I found a solution:

<img src="orig_image.jpg" onerror="this.src='alt_image.jpg';">



  #4  
Old July 23rd, 2005, 09:01 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a

re: Alternative Image


joe wrote:
[color=blue]
> Ok. I think I found a solution:
>
> <img src="orig_image.jpg" onerror="this.src='alt_image.jpg';">[/color]

This is not a standards compliant solution, though. The `img' element
does not have an `onerror' attribute in Valid (X)HTML markup, and the
`alt' attribute is required. A standards compliant solution, taking
into account additional DOM features, could be

<!-- Transitional HTML or XHTML DOCTYPE, else use `id' instead of `name' -->
<html>
<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function replaceOnError(img, alt_src)
{
if (typeof img.onerror != "undefined")
{
img.onerror = function()
{
this.src = alt_src;
return true;
}
}
}
</script>
...
</head>

<body onload="replaceOnError(document.images['foo'], 'alt_image.jpg');">
...
<img src="orig_image.jpg" alt="foo" name="foo">
...
</body>
</html>

But you rather should consider the ErrorDocument directive of httpd
compatible Web servers (like the Apache HTTP Server) which will also
work without client-side script support.


PointedEars
  #5  
Old July 23rd, 2005, 09:02 PM
commercial
Guest
 
Posts: n/a

re: Alternative Image


What garble are you talking about ?

Image loads or not and will not error otherwise.

I you need to event monitor higher stuff,
it may be too late.


What error? Do your local newspaper's photos
make noises when you pull a copy form the vending box.

Which one you thought ?

How is your noisy cartoon and TV replacement of a childhood
and education playing out after all ?


"Alternative Image"

There is no such thing. I means otherwise, how e.g. blind people
ought to be presented an idea of an "invisible picture"
in TEXTUAL representation.

And that must not make an error or noise on demand only.

You sure are not an eye dog in this group.







"Thomas 'PointedEars' Lahn" <PointedEars@web.de> wrote in message
news:1188121.KGGzIapAWZ@PointedEars.de...[color=blue]
> joe wrote:
>[color=green]
> > Ok. I think I found a solution:
> >
> > <img src="orig_image.jpg" onerror="this.src='alt_image.jpg';">[/color]
>
> This is not a standards compliant solution, though. The `img' element
> does not have an `onerror' attribute in Valid (X)HTML markup, and the
> `alt' attribute is required. A standards compliant solution, taking
> into account additional DOM features, could be
>
> <!-- Transitional HTML or XHTML DOCTYPE, else use `id' instead of[/color]
`name' -->[color=blue]
> <html>
> <head>
> ...
> <meta http-equiv="Content-Script-Type" content="text/javascript">
> <script type="text/javascript">
> function replaceOnError(img, alt_src)
> {
> if (typeof img.onerror != "undefined")
> {
> img.onerror = function()
> {
> this.src = alt_src;
> return true;
> }
> }
> }
> </script>
> ...
> </head>
>
> <body onload="replaceOnError(document.images['foo'], 'alt_image.jpg');">
> ...
> <img src="orig_image.jpg" alt="foo" name="foo">
> ...
> </body>
> </html>
>
> But you rather should consider the ErrorDocument directive of httpd
> compatible Web servers (like the Apache HTTP Server) which will also
> work without client-side script support.
>
>
> PointedEars[/color]

  #6  
Old July 23rd, 2005, 09:15 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a

re: Alternative Image


"commercial" schrieb:
[color=blue]
> [...]
> "Alternative Image"
>
> There is no such thing. I means otherwise, how e.g. blind people
> ought to be presented an idea of an "invisible picture"
> in TEXTUAL representation.[/color]

(This is the only part of your posting with some meaning, so I'll reply
to it.)

Well, the `alt' property of the respective HTMLImageElement and so the
`alt' attribute of the related `img' element can be changed as well.
That would result in different presentation on error for users without
image support, too.
[color=blue]
> And that must not make an error or noise on demand only.
>
> You sure are not an eye dog in this group.[/color]

I am sure that you are not really know to whom you are replying, or
rather yelling, what.
[color=blue]
> [Top post, full quote][/color]

You may also want to read the newsgroup's FAQ and FAQ notes.


PointedEars
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to specify alternate image?? Chittaranjan answers 1 July 9th, 2007 03:34 PM
alternative for outerHTML property which is supported by Mozilla firefox browser prasaddevivara answers 1 July 23rd, 2005 09:23 PM
What can I do so that this image can be saved? George Hester answers 14 July 23rd, 2005 03:39 PM
Locking a PHP image from remote web pages ywg answers 5 July 17th, 2005 05:10 AM