最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - How do I include a javascript if it's IE, and another javascript if everything else? - Stack Overflow

programmeradmin3浏览0评论

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 badges
Add a ment  | 

3 Answers 3

Reset to default 11

You 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).

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论