Lucky
Lucky

Reputation: 17345

Dont run a javascript function in IE

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

Upvotes: 0

Views: 1507

Answers (2)

Jorge Y. C. Rodriguez
Jorge Y. C. Rodriguez

Reputation: 3449

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;?>

Upvotes: 0

Quentin
Quentin

Reputation: 943537

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.

Upvotes: 3

Related Questions