简体   繁体   English

如何检测IE 10+的onerror事件

[英]How to detect IE 10+ for an onerror event

I have a little problem with scaling SVG on IE10+. 我在IE10 +上缩放SVG有点问题。 I have this code: 我有以下代码:

<img src="img/logo.svg" alt="" onerror="this.src='img/logo.png'; this.onerror=null;">

How can I detect IE10+ for the onerror event? 如何为onerror事件检测IE10 +?

Greetings 问候

For IE10+, use the Microsoft specific window.msMatchMedia feature detection: 对于IE10 +,请使用Microsoft特定的window.msMatchMedia功能检测:

 function handler(e) { if (!!window.msMatchMedia) { e.target.src = "http://stackoverflow.com/favicon.ico"; } } document.querySelector("#ie10_plus").addEventListener("error", handler, false) 
 <img src="" id="ie10_plus" alt=""> 

In general, use an invalid src value to trigger an error. 通常,使用无效的src值来触发错误。 For example: 例如:

 document.querySelector('#foo').src="//foo"; 
 <img src="" width="16" height="16" onclick="javascript:this.src='http://www.stackexchange.com/favicon.ico'"/>Click Me <img src="favicon.ico" onerror="javascript:this.src='http://stackoverflow.com/favicon.ico'" width="16" height="16"/>Despicable Me <img id="foo" src="" width="16" height="16" onerror="javascript:this.src='http://stackoverflow.com/favicon.ico'"/>Despicable Me 2 

References 参考文献

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM