Loading js file for all browsers except IE I have a requirement to add a js file only for IE (6, 7, 8) browsers. The following script works fine and sometime it doesn't. I cleared the cache several times but has no difference.I don't know where I am going wrong . Is there anything to do with drupal_add_js for IE?

function mymodule_init() {
  if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
    $theme_path = drupal_get_path('theme', 'mythemename');
    $js_path = $theme_path . '/script/modernizr.js';
    drupal_add_js($js_path, 'external');
  }
}

// The code modified to true for all browsers it works for all browsers but not in IE 
function mymodule_init() {
  if(1)) {
    $theme_path = drupal_get_path('theme', 'mythemename');
    $js_path = $theme_path . '/script/modernizr.js';
    drupal_add_js($js_path, 'external'); // loading in all browsers except IE
  }
}
As you may be suspected, the original condition is wrong.  Here's a related post on how someone was able to find a better condition for checking the user agent for IE:

https://stackoverflow.com/questions/5302302/php-if-internet-explorer-6-7-8-or-9

summary: use this instead:

if(preg_match('/(?i)msie [1-8]/',$_SERVER['HTTP_USER_AGENT'])){}