running specific code in js file pertaining to i.e9 v's all other browsers

94 views Asked by At

so it has come down to this one line of code... I am basically trying to create a part in my code that says do this if i.e9 but if not do this... here is the code...

('.fa-phone, .bg-darkPink').parent().on('click', function () {
      $('.submenu-ctn').fadeTo(0, 0);



<<--IF I.E9 OR BELOW DO THIS THING--->>
    $('#menu').multilevelpushmenu({
            Collapsed: true



              });
          <<--END OF I.E9 OR BELOW THING ----->>

  <<--I.E9 MUST ALSO IGNORE THIS LINE IN THE SCRIPT --->> 
  $( '#menu' ).multilevelpushmenu( 'collapse' );

$MORE CODE 
$MORE CODE

it is part of a string of functions associated with a button.. for some reason i.e9 didn't like the function but the other way it did.. any help here would be awesome ...

p.s I am using modernizr 2.6.2 so have been reading up on its feature detection capabilities but can't get my head round it , please someone put me out of my misery ;p

beggining of solution EDIT

So far I have this ...

 $('.fa-phone, .bg-darkPink').parent().on('click', function () {
      $('.submenu-ctn').fadeTo(0, 0);
      $('.submenu-ctn').fadeTo(3000, 1); 
      $("#colorscreen").remove();
      $("body").append('<div id="colorscreen" class="animated"></div>');
      $("#colorscreen").addClass("fadeInUpBigCS");
      $(".tile-area-main").css({width: "720px",opacity:1}).load("contact-page.html #contact-form");
      $.getScript("js/slider/slider-animations.js");
      $(".submenu-ctn").load("contact-page.html .submenu-contact");
      $('.nav-toggle').removeClass('active');
      $(this).addClass('active');  

      if(browser.name=='msie'&&browser.version<=9) { 
       $('#menu').multilevelpushmenu({Collapsed: true}); 
       }else { 
       $( '#menu' ).multilevelpushmenu( 'collapse' ); }

});
2

There are 2 answers

8
Ajay Narain Mathur On BEST ANSWER

You can use conditional comments in html:

<!--[if lte IE 9]>
  // Include script for ie9 and less here
<![endif]-->

Update:

You can use navigator object in Script to detect if it is ie9 or below.

navigator.appVersion

It return this:

clientVersion (platform; information; extraInformation)

example:

5.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90)

Check the following link

Here is the code:

var flag = false;
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
function checkVersion()
{
  var msg = "You're not using Internet Explorer.";
  var ver = getInternetExplorerVersion();

  if ( ver > -1 )
  {
    if ( ver == 9.0 ) 
      flag = true
    else
      flag = false
  }else{
  flag = false
}
}

Now check in you function if flag is true call the function else jump through

Update 3:

var ms_ie = false;
var ua = window.navigator.userAgent;
var old_ie = ua.indexOf('MSIE ');
var new_ie = ua.indexOf('Trident/');

if ((old_ie > -1) || (new_ie > -1)) {
    ms_ie = true;
}

if ( ms_ie ) {
    //IE specific code goes here
}

Try this code

$('.fa-phone, .bg-darkPink').parent().on('click', function () {
      $('.submenu-ctn').fadeTo(0, 0);
      $('.submenu-ctn').fadeTo(3000, 1); 
      $("#colorscreen").remove();
      $("body").append('<div id="colorscreen" class="animated"></div>');
      $("#colorscreen").addClass("fadeInUpBigCS");
      $(".tile-area-main").css({width: "720px",opacity:1}).load("contact-page.html #contact-form");
      $.getScript("js/slider/slider-animations.js");
      $(".submenu-ctn").load("contact-page.html .submenu-contact");
      $('.nav-toggle').removeClass('active');
      $(this).addClass('active');  

// code started here

var ms_ie = false;
    var ua = window.navigator.userAgent;
    var new_ie = ua.indexOf('Trident/5');   //only for ie9

    if ((new_ie > -1) {
        ms_ie = true;
    }

    if ( ms_ie ) {
        $('#menu').multilevelpushmenu({Collapsed: true}); 
        }else{
    $( '#menu' ).multilevelpushmenu( 'collapse' );
    }
    });
10
depperm On

From How can you detect the version of a browser?, second answer, use an if

if(browser.name=='msie'&&browser.version<=9)
   //do your stuff