html5 error,html - HTML5 video error handling - Stack Overflow

从Firefox4开始,视频元素会触发'error'事件。你可以为最后一个source元素添加错误处理程序,例如使用纯JavaScript或jQuery,甚至在AngularJS中创建一个错误处理指令。这些方法在视频加载出错时弹出警告。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

From Firefox 4 onwards, the 'error' event is dispatched on the element.

And you should add an error handler on the only/last source:

HTML

JS

var v = document.querySelector('video#vid');

var sources = v.querySelectorAll('source');

if (sources.length !== 0) {

var lastSource = sources[sources.length-1];

lastSource.addEventListener('error', function() {

alert('uh oh');

});

}

JQuery

$('video source').last().on('error', function() {

alert('uh oh');

});

AngularJS

You can create an error handling directive (or just use ng-error):

Where the error handling directive's link function should do (copied from ng-error):

element.on('error', function(event) {

scope.$apply(function() {

fn(scope, {$event:event});

});

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值