mootools_使用MooTools AJAX发送破碎图像的电子邮件通知

mootools

One of the little known JavaScript events is the image onError event. This event is triggered when an image 404's out because it doesn't exist. Broken images can make your website look unprofessional and it's important to fix broken images as soon as possible. I've created a MooTools / PHP script that listens for image errors, triggers an AJAX call to a PHP script, and that PHP script sends an email letting me know about the problem.

鲜为人知JavaScript事件之一是图像onError事件。 当图像404由于不存在而被触发时,会触发此事件。 损坏的图像可能会使您的网站看起来不专业,因此尽快修复损坏的图像很重要。 我创建了一个MooTools / PHP脚本,该脚本侦听图像错误,触发对PHP脚本的AJAX调用,并且该PHP脚本发送一封电子邮件,让我知道该问题。

MooTools JavaScript (The MooTools JavaScript)


window.addEvent('domready',function() {
	$$('img').addEvent('error',function() {
		var notification = new Request({
			url: 'ajax-image-error.php',
			method: 'post',
			data: {
				'image': this.get('src'),
				'page': window.location.href
			}
		}).send();
	});
});


You'll notice that I listen for the error event. You'll also notice that I only send two parameters: the image path and the page the broken image is living (or dying) on.

您会注意到我在监听错误事件。 您还将注意到,我仅发送两个参数:图像路径和残破的图像赖以生存(或垂死)的页面。

PHP (The PHP)


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);
}


Nothing special within the email -- just the parameters we put into the AJAX call. This bare email will provide us enough information to solve the problem.

电子邮件中没有什么特别的-仅是我们放入AJAX调用中的参数。 这封裸露的电子邮件将为我们提供解决问题的足够信息。

One addition to the MooTools script could be to remove the image from the page so that the user doesn't notice the problem. Have any suggestions? Share them!

MooTools脚本的另一项功能可能是从页面上删除图像,以使用户不会注意到该问题。 有什么建议吗? 分享他们!

翻译自: https://davidwalsh.name/email-image-error-mootools

mootools

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值