Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1063053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:43:34+00:00 2026-05-16T18:43:34+00:00

I want to include a JavaScript file only if the browser is not IE.

  • 0

I want to include a JavaScript file only if the browser is not IE. Is there any way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:43:35+00:00Added an answer on May 16, 2026 at 6:43 pm

    Update 2022:

    Some options for you:

    1. Have your server look at the User-Agent header and send different HTML to Internet Explorer vs. other browsers.

      Pros:

      • No client-side solution required.

      Cons:

      • Relying on User-Agent strings is notoriously error-prone, and they can be spoofed or entirely absent.
    2. Sniff navigator.userAgent and either output a script tag or not depending on what you find.

      Pros:

      • No server-side requirement.

      Cons:

      • Same as #1: Relying on User-Agent strings is notoriously error-prone, and they can be spoofed or entirely absent.
      • Some people have an issue with outputting script tags from code, particularly via document.write, but depending on your use case document.write may be unavoidable (e.g., do you need the script there before some other script, etc.).
    3. Sniff for something in the JavaScript runtime that only Internet Explorer has, and output a script tag or not based on what you find.

      Pros:

      • No server-side requirement.
      • No user-agent sniffing.

      Cons:

      • The issue some people have with dynamically adding script tags.

    I’d probably look at #3. For instance, any even vaguely modern browser has the Symbol function. Internet Explorer does not. So:

    if (typeof Symbol !== "undefined") {
        document.write("<script src='./your-non-ie-script.js'><\/script>");
        // Or if you prefer
        let script = document.createElement("script");
        script.src = "./your-non-ie-script.js";
        document.activeElement.parentNode.appendChild(script);
    }
    

    Symbol is just one example, IE lacks Reflect, Proxy, and a few others from ES2015 that everything else has now…

    (Not sure why I didn’t mention this in 2013!)


    Update 2013: IE10+ don’t support conditional comments anymore.


    You can do it with IE’s conditional comments, like so:

    <![if !IE]>
    <script src="your-non-IE-script.js" type="text/javascript"></script>
    <![endif]>
    

    Note that the above is processed by non-IE browsers because the conditional is not an HTML comment, but a processing instruction, so the bit in the middle is processed by non-IE browsers. IE sees the conditional and skips over the content because it understands the conditional means "Not you, move along."

    If you want to do something only for IE, you use a form that’s similar, but uses HTML comments instead (with the --) because that’s the only way you can rely on other browsers ignoring the contents. IE knows to pay attention to them, even though they’re comments. More on the link above.

    Note that there’s a page load speed implication on IE (not the other browsers) when you use conditional comments (they temporarily block download of other resources), more here: http://www.phpied.com/conditional-comments-block-downloads/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I only want this JavaScript to be included in the response to the
I have an external javascript file that I want to, upon include, write some
I want to server the 'excanvas.min.js' file only to the Internet Explorer and not
How do you include a javascript or CSS file only on a certain article
Possible Duplicate: How to include a JavaScript file in another JavaScript file? I want
I want to insert the following include tag into my webpage using JavaScript. <!--#include
I want to include an admob banner in my application and I got this
I want to include a php file in a div box whenever one generated
I want to include jQuery UI in my jsp page. I tried this <jsp:root
The problem: I want to use PHP include to import file header_menu.html into all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.