jquery判断图片是否完整加载了

来源:互联网 发布:软件需求说明书模板 编辑:程序博客网 时间:2024/04/29 18:03
这里其实是个tips,目的是判断每张图片是否能正确完整加载了:
(document).ready(function() {
$('img').error(function() {
  $.post('ajax-image-error-jquery.php', {
   image: $(this).attr('src'),
   page: window.location.href
  }, function() {
   //hide the image?
  });
});
});
对于每个图片,监听其中的error事件即可,然后POST到一个PHP去处理,把其中的SRC参数带过去,比如可以发邮件通知:
if(isset($_POST['image']))
{
$to = 'errors@yourdomain.com';
$from = 'automailer@yourdomain.com';
$subject = 'Broken Image';
$content = "The website is signaling a broken image!\n\nBroken Image Path:  ".stripslashes($_POST['image'])."\n\nReferenced on Page:  ".stripslashes($_POST['page']);
$result = mail($to,$subject,$content,'From: '.$from."\r\n");
die($result);
}



原创粉丝点击