[英]How to remove a script if browser is IE10
如果瀏覽器是IE10,如何刪除腳本?
我試着這樣做:
<!--[if !IE]-->
<script type="text/javascript" src="js/script.js"></script>
<!--[endif]-->
但由於IE10不再支持條件注釋,它仍然會加載腳本。
有任何想法嗎?
在代碼中使用功能檢測,而不是瀏覽器嗅探。
瀏覽器嗅探是不可靠的,並且隨機變化。 檢測用戶代理功能是迄今為止更好的編碼方法。
如果瀏覽器不是IE10,則可以通過在javascript中使用此代碼將此腳本標記附加到頭中來實現此目的:
**//detect IE10**
var isIE10 = false;
/*@cc_on
if (/^10/.test(@_jscript_version)) {
isIE10 = true;
}
@*/
if(!isIE10){
**//append script tag to head if not IE10**
var script = document.createElement('script');
script.type = '"text/javascript"';
script.src = 'js/script.js';
document.head.appendChild(script);
}
我希望這可以幫到你。 謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.