我想在对象标记中显示一些内容,但是如果对象的目标无法加载,我想向用户显示特定的错误消息。这是我的代码:
<object id="foo"></object>
<script>
document.getElementById('foo').addEventListener('error', function() {
alert('error');
});
document.getElementById('foo').data = 'http://localhost/doesnotexist';
</script>
错误处理程序永远不会运行。我做错了什么?