Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #38644
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2020-08-04 02:18 -0700 |
| References | <mICdnUE2Q-twd7XCnZ2dnUU7-fvNnZ2d@westnet.com.au> |
| Message-ID | <17dbfe7e-6f69-4976-ae76-eed1631dfcbco@googlegroups.com> (permalink) |
| Subject | Re: missing image error |
| From | Julio Di Egidio <julio@diegidio.name> |
On Tuesday, 4 August 2020 06:58:31 UTC+2, Andrew Poulos wrote:
> I'm dynamically adding images to a page using
>
> let img = new Image();
>
> img.src = 'images/' + name + '.jpg';
> img.setAttribute("onerror", "this.onerror=null;
> this.src='images/imagenotfound.png'");
> ...
>
> and the page works as expected. That is, when the image is not available
> 'imagenotfound' is shown in its place.
>
> The client tests the page with the console open and each time an image
> is unavailable they see a 404 error. I've tried explaining that it needs
> to error before it can know to replace it with 'imagenotfound' but they
> would prefer that image's 404 error not show.
>
> Is there a way to trap the 404 so it doesn't show in the console?
>
> Or is there some other way I can try to get the image and thereby be
> able to trap the 404?
As Mr Welzel was pointing out, the server is returning an HTTP error 404,
which is the error you are then handling, i.e. the error has to happen.
OTOH, (I think) in most consoles there is an option to suppress reporting
network errors in the console: if you really need to... But you might
want to tell your customer that they should NOT look at the dev console
unless they can stand it. ;)
Julio
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
missing image error Andrew Poulos <ap_prog@hotmail.com> - 2020-08-04 14:58 +1000
Re: missing image error Arno Welzel <usenet@arnowelzel.de> - 2020-08-04 10:29 +0200
Re: missing image error James Kirk <noneya.invalid@gmail.com> - 2020-08-04 22:38 -0400
Re: missing image error Arno Welzel <usenet@arnowelzel.de> - 2020-08-05 07:49 +0200
Re: missing image error Julio Di Egidio <julio@diegidio.name> - 2020-08-04 02:18 -0700
Re: missing image error Andrew Poulos <ap_prog@hotmail.com> - 2020-08-05 13:20 +1000
Re: missing image error Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-08-05 08:44 +0200
Re: missing image error Andrew Poulos <ap_prog@hotmail.com> - 2020-08-05 18:02 +1000
Re: missing image error Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-08-05 10:18 +0200
Re: missing image error Julio Di Egidio <julio@diegidio.name> - 2020-08-05 02:36 -0700
csiph-web