admin管理员组文章数量:1333710
i have some images that get displayed on a page, some of them don't get loaded and i see that non-loading :) small icon.
i was wondering if there is a way to check if the image loaded successful and if not now to display it
this is my image code:
print "<a href=\"".$domain."/picture.php?s=".$s2."&media_path=".$media_path."\">";
print "<img src=\"".$domain."/".$folder."/".$media_path."\" >";
print "</a>";
what happens is that picture.php looks in the database for the picture name and path and builds the link.
I've looked in the database and the data is there so the images mush be corrupted on the drive, maybe wrong image
So i need some way to check if the image is loaded with success at the end of the script. preferable in php but javascript/jquery is fine also
edit: from the answers i got i did this:
function hideImage()
{
$('.hideme_image').hide();
}
print "<a class=\"hideme_image\" href=\"".$domain."/picture.php?s=".$s2."&media_path=".$media_path."\">";
print "<img onerror=\"hideImage()\" src=\"".$domain."/".$folder."/".$media_path."\" >";
print "</a>";
this hides all images, but not all images are corupted.
any ideas?
thanks
i have some images that get displayed on a page, some of them don't get loaded and i see that non-loading :) small icon.
i was wondering if there is a way to check if the image loaded successful and if not now to display it
this is my image code:
print "<a href=\"".$domain."/picture.php?s=".$s2."&media_path=".$media_path."\">";
print "<img src=\"".$domain."/".$folder."/".$media_path."\" >";
print "</a>";
what happens is that picture.php looks in the database for the picture name and path and builds the link.
I've looked in the database and the data is there so the images mush be corrupted on the drive, maybe wrong image
So i need some way to check if the image is loaded with success at the end of the script. preferable in php but javascript/jquery is fine also
edit: from the answers i got i did this:
function hideImage()
{
$('.hideme_image').hide();
}
print "<a class=\"hideme_image\" href=\"".$domain."/picture.php?s=".$s2."&media_path=".$media_path."\">";
print "<img onerror=\"hideImage()\" src=\"".$domain."/".$folder."/".$media_path."\" >";
print "</a>";
this hides all images, but not all images are corupted.
any ideas?
thanks
Share Improve this question edited Jan 18, 2012 at 23:35 Patrioticcow asked Jan 18, 2012 at 23:25 PatrioticcowPatrioticcow 27.1k76 gold badges221 silver badges339 bronze badges2 Answers
Reset to default 7<img src="image.png" onload="alert('Image loaded');" onerror="alert('Image failed');" />
Something along these lines, is what you're looking for, I think.
You can use onload
event on the image
tag. Please have a look at this example from W3Schools.
本文标签: how to check if a image is loaded with success in php or javascriptStack Overflow
版权声明:本文标题:how to check if a image is loaded with success in php or javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742274435a2444926.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论