[英]How to detect IE 10+ for an onerror event
我在IE10 +上縮放SVG有點問題。 我有以下代碼:
<img src="img/logo.svg" alt="" onerror="this.src='img/logo.png'; this.onerror=null;">
如何為onerror事件檢測IE10 +?
問候
對於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="">
通常,使用無效的src
值來觸發錯誤。 例如:
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
參考文獻
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.