0

How to not run a javascript function in IE.I'm having a number of functions in my javascript file..While i need to stop some script from running in Internet explorer. I know the below code is used to run this script file if not IE..

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

How can i skip some function in js..like below I tried to skip the method b in IE..but it dont work..

function a{alert(a);}
<!--[if !IE]>
function b{alert(b);}
<![endif]-->
function c{alert(c);}
function d{alert(d);}

but the method b is always called..How can i prevent it from running in IE browsers..

5
  • Put it in it's own script tag? Commented Sep 16, 2013 at 10:21
  • 1
    possible duplicate of Detect IE version in Javascript Commented Sep 16, 2013 at 10:22
  • Man, you're in muddy waters ... Commented Sep 16, 2013 at 10:22
  • 2
    Why modernizer @ShashiBhushan, that it is adding another extra library for something it can work better in pure js ... Commented Sep 16, 2013 at 10:23
  • 1
    Presumably you want to not run something in IE because it's missing features, or something? The point of using Modernizr is that instead of targeting a particular browser, you base it on available features - so if there are any other smaller browsers that are also missingthose features, then your site doesn't break by making incorrect assumptions. Commented Sep 16, 2013 at 10:32

2 Answers 2

3

IE10 doesn't support conditional comments.

If you don't want to run a function in some browsers, then suppress it with feature (AKA object) detection, not user agent detection.

Sign up to request clarification or add additional context in comments.

Comments

0

Actually what i do it is a bit nasty, but if there is some functions i don't want to run in IE I add this ::

    <?php if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') == false)):?>

       <script src="js/noIEfunctions.js"></script>

    <?php endif;?>

2 Comments

FWIW, this code will not work in IE11. User-Agent sniffing is evil and should be avoided.
The IE team took out the MSIE token explicitly to break code that was doing foolish User-Agent detection instead of proper capabilities detection. Many webpages work just fine in IE10 or IE11 but due to outdated UA-string checks the pages weren't working. Hence the change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.