I want to in开发者_运维技巧clude <script src="ie.js">
if the browser is IE.
Otherwise, include all.js
for all other browsers.
How can I do this?
You can do this using conditional comments. Example:
<!--[if IE]>
<script src="ie.js">
<![endif]-->
<!--[if !IE]><!-->
<script src="all.js"></script>
<!--<![endif]-->
I was looking for something similar, and so far the simplest solution I found is to do a JS based condition to check the document.documentMode property: https://www.w3schools.com/jsref/prop_doc_documentmode.asp
I hope this will help someone else who stumble on this thread in Google results like I did.
Conditional comments only work in IE, and are thus excellently suited to give special instructions meant only for IE. They are supported from IE 5 up until IE9 (inclusive).
精彩评论