-1

I am tasked to put jQuery into a webapp, needful of functionality specific to the Internet Explorer 8 browser (7 is not needed). How to do this?

In jQuery 1.8 could do:

if ($.browser.msie && $.browser.version == '8') { /* does not matter */ }

In version 1.9 $.browser is removed. The recommended $.support does not help.

kapa
  • 77,694
  • 21
  • 158
  • 175
PRASHANT P
  • 1,527
  • 1
  • 16
  • 28
  • I dont think I understand the question. Are you trying to add jQuery to IE8? If so, what exactly is it your trying to add? – Robert Mailloux Mar 06 '13 at 21:55
  • You only want to load jQuery for Internet Explorer 8? Is a different version loaded for IE9+? – Sampson Mar 06 '13 at 21:56
  • mr sampson, goal is FUNCTION execute only when user bowser of IE 8 – PRASHANT P Mar 06 '13 at 22:03
  • 1
    Stop doing browser detection. Tell us what you have that doesn't work in IE8 and we can probably help you make it work in IE8 without having to remove functionality. – Kevin B Mar 06 '13 at 22:43

2 Answers2

7

Browser detection vs. feature detection

$.browser is deprecated from jQuery for a reason (since 1.3). Using it for stuff like you wanted to use it for is not a recommended practice. If you are depending on a certain feature, test for that feature (this is called feature detection, $.support is one way to do this) instead of testing for a specific browser.

Conditional Comments

If you really need to target old IE, use conditional comments (can easily be removed when old IEs do not exist anymore and does not bloat other browsers unnecessarily):

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

Inside my_ie8_specific_stuff.js you can write anything you need, it will only be executed on IE8.

Conditional class on the <html> element

Another way of doing it is putting a class on your <html> tag with conditional comments:

<!--[if IE 8]>         <html class="ie8"> <![endif]-->
<!--[if gt IE 8]><!--> <html>         <!--<![endif]-->

This clever and tricky technique will put an ie8 class on html in IE8, any other browser will not get it.

You can easily check for this in jQuery:

var isIE8 = $('html').hasClass('ie8');
Community
  • 1
  • 1
kapa
  • 77,694
  • 21
  • 158
  • 175
  • is of not possible, FUNCTION locate inside PLUGIN - no reason for script incluse file multiply – PRASHANT P Mar 06 '13 at 22:07
  • @PRASHANTP No reason for your script to include IE8 specific stuff, that's what I say. But I added another technique you might find useful. – kapa Mar 06 '13 at 22:08
-2

If by chance you're using Kendo in your app you don't have to add anything. A class is automaticly generated when you're in the different browsers. If you want to check if it's ie8, you can do it simply like that:

if($('html').hasClass('k-ie8'))
    // do something
ParPar
  • 7,355
  • 7
  • 43
  • 56
  • Some kind of framework, library, etc., either client or server side, adds these classes for you. So your answer is not really useful until you find out what is adding these classes, and even then, it will be too specific to help. In my answer I outlined the technique which should be used to add these classes to ``. – kapa May 11 '14 at 08:36