MyBB Community Forums

Full Version: Automatically replace broken images?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hey!
A lot of users post images on my website. I want something so if the image is not found, it will get replaced by an image hosted on the server "imagenotfound.png", or something.
Like:
<img src="notfound.png" onError="this.src='imagefound.gif';">
I just don't know how to automatically add the "onerror" for every image?

Thanks!
You could probably do it with javascript:

$('img').attr('onError', 'this.src="imagefound.gif"');
Where to put this code?
Best place would probably be the showthread template, after:

lang.editreason = "{$lang->postbit_editreason}";

add:

$(document).ready(function() {
    $('img').attr('onError', 'this.src="imagefound.gif"');
});
Thank you very much!
Pretty nice idea. This could be useful for others too, actually.
Good idea!
This could potentially be improved by adding a callback function which sends to the backend the actual image URL with AJAX. Then, using the tasks system, it would replace the broken images in the actual database's posts in such a way that you don't have to see a FOUC every time. Too bad I am working on something else.
Maybe when you find some free time +)
Is possible to show the text instead of image (notfound)? Something like <div class="notfound">[Image is not available...]</div> with css class for easier customization. Thank you in advance!

OK, I had been trying to solve this with my poor knowledge of JS. Unfortunately without success.

My request:
- I would like to show <div> with text (notice, about 4-5 words) instead of notfound image

Please, is there anybody who can show me the proper code for this? Thank you very much!
Pages: 1 2