We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

Workaround for broken images in Newsfeed | Forum

fbkca
fbkca Oct 1 '13

Hi, 


So it seems it will be a while before anything can be done about this. So I've come up with a way to hide any of those pesky broken images you now see in the Newsfeed should one of the images be deleted. I forget the original source.


This isn't the ideal solution but works for me. Just enter this code the Custom Head Code of the admin/settings/page section of your Admin panel. The code is attached as well. You will see a broken image for a very brief moment (depends on your server speed), as the images are only removed/hidden once the page is completely loaded, so as to not miss any.


<script>

function ImageOk(img) {

// If the body has finished loading and img is not complete then

// you  have a broken image so return false - image is broke

if (!img.complete) return false;


// if naturalWidth is undefined or zero then the image failed to load

// so return false - image is broke

if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) return false;


// When all checks passed - image is ok

return true;

}


function BrokenImageCheck() {

// Define your image to replace the broken on

// Not necessary if you are going to use the "none" option below


var replacementImg = "/images/NoPhotoOnFile.gif";


// Go through all the images

for (var i = 0; i < document.images.length; i++) {

if (!ImageOk(document.images[i])) {

// If image did not finish loading choose your option

// use the replacementImg line to show your replacement image

// use the "none" line to hide the image completely

// None is uncommented by default


// document.images[i].src = replacementImg;

document.images[i].style.display = "none";


}

}

}


// After body loads check all images to see if they successfully loaded

window.onload=BrokenImageCheck;

</script>



That's it. Enjoy.


This is provided as-is.

The Forum post is edited by fbkca Oct 4 '13
Attachments:
  newsfeed_broken_images.txt (1.13Kb)
Alia Team
Alia Oct 2 '13
fbkca, thanks for sharing.
Worked for me as well.
Dave S
Dave S Oct 4 '13
Many thanks fbkca! You rock!
dave Leader
dave Oct 4 '13

Thanks i have also updated my thread from a while back

http://www.oxwall.org/forum/topic/13090

 

 to point here...thanks :)  def a step in the right direction ;)

Lee
Lee Oct 6 '13
Is the code will make any other change to the site or it only fix broken images?
fbkca
fbkca Oct 6 '13
It's only for broken images .