I want to include <script src="ie.js">
if the browser is IE.
Otherwise, include all.js
for all other browsers.
How can I do this?
I want to include <script src="ie.js">
if the browser is IE.
Otherwise, include all.js
for all other browsers.
How can I do this?
Share Improve this question edited Mar 2, 2014 at 6:28 abatishchev 100k88 gold badges301 silver badges442 bronze badges asked Jul 19, 2011 at 4:11 TIMEXTIMEX 272k367 gold badges801 silver badges1.1k bronze badges3 Answers
Reset to default 11You can do this using conditional ments. 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./jsref/prop_doc_documentmode.asp
I hope this will help someone else who stumble on this thread in Google results like I did.
Conditional ments 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).