views:

44

answers:

1

Hi,

I have a JQuery-Datepicker that (however) crashes my site when you are using IE6. So I want the site to prevent the loading of that particular javascript on IE6.

I know about this trick:

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

But I need it the other way around: To load the Script if the browser is NOT IE 6. This will not work, since Mozilla & Co. will see just a simple comment:

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

So, what's the best solution for this problem? Any ideas?

Thanks in advance.

+1  A: 
var loadLibrary = true;
<!--[if IE 6]>
  loadLibrary = false;
<![endif]-->

if(loadLibrary)
{
   var s = document.createElement("script");
   s.setAttribute("type", "text/javascript");
   s.setAttribute("src", "datepicker.js");
   document.getElementsByTagName("head")[0].appendChild(s);
}
Matthew Flaschen
that looks like javascript. but i am not sure, if there is a way to load a external javascript-file within a javascript-function.Could you be a little bit more specific, how the "..." would do something equivalent to: <script type="text/javascript" src="datepicker.js"></script>
AlphaOne