How would I use an only for IE8 and not for any other browser

52 Views Asked by At

I'm currently using jquery 3.0 on a site. I understand that support for IE8 was dropped in Jquery 2, but is there a way to use jquery 1.9 for IE8 and use Jquery 3.0 on any other browser?

2

There are 2 best solutions below

0
On BEST ANSWER

You can try to use HTML conditional statements. It is an oldschool way of doing this and little bit extreme ( but you are targeting IE8, anyways).

More here. Even better here

Here is what I have in mind:

<!--[if IE8]><script src="jquery2.0.js" "><![endif]-->
<!--[if IE9]>include something else [endif]-->
0
On

This seems like a lot more work than it is worth. So many features are deprecated between the previous and current versions of jQuery, you're going to have to write code twice in many scenarios, rather than simply add something simple like a <noscript>. This also can lead to a lot of code collision and bugs which wouldn't occur otherwise. Lastly, users can always edit their agent string and completely bypass your intent, which is a fairly common event on the internet.

That being said, the code you want is: var foo = navigator.userAgent;

You'll want to compare foo to the known user agent strings and then add in your jQuery calls to the appropriate jQuery version, using pure JavaScript. I'd also suggest you switch your code based on the value of foo to minimize the code clash.

You have two alternatives that may also work:

  • Write a page that checks for the userAgent and then sends the user onward to a page coded for jQuery 2 or 1.
  • If you can, convince your boss (or customer, etc.) to drop IE8 support, if possible. As of time of this response, IE is only 15.6% of the market, with IE 8 not even ranking on the top 10 browsers in use based on W3Counter's metrics. This means no switch is needed at all and you save coding time.