我试图了解Chrome的html导入实现,例如
<link id="test_component" rel="import" href="http://localhost:8888/fail.html" onerror="handler(event)">
然而,错误事件并未真正传达MDN中指定的有用信息。我想知道是否有任何方法可以从错误事件中获得更多信息,例如失败原因和HTTP状态代码。
答案 0 :(得分:2)
如果触发了错误事件处理程序,您可以使用XMLHttpRequest
或fetch
重播请求,以获取有关失败的更多信息。
function handler(event)
{
fetch(event.target.href)
.then( resp => console.info(resp.status) )
.catch( err => console.log(err) )
}