iker30
iker30

Reputation: 21

How to remove a script if browser is IE10

How can I remove a script if the browser is IE10?

I tried to do it like this:

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

But since IE10 doesn't support conditional comments anymore, it still loads the script.

Any ideas?

Upvotes: 1

Views: 578

Answers (2)

Pushpak
Pushpak

Reputation: 148

You can achieve this by appending this script tag in head if the browser is not IE10 by using this code in 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);
    }

I hope this may help you. Thanks.

Upvotes: 2

itmitica
itmitica

Reputation: 511

Use feature detection in your code, not browser sniffing.

Browser sniffing is unreliable and subject to random changes. Detecting user agent capabilities is by far a better approach to coding.

Upvotes: 1

Related Questions