0

Im trying to perform two different scripts depending on if its IE11 or not

Consider the following pseudo code

<td>
  if IE11 
    perform  IE11_Code
  else
    perform  other_code
  end if
</td>

How can I archive this.

Detecting IE11 apparently works like this.

var isAtLeastIE11 = !!(navigator.userAgent.match(/Trident/) && !navigator.userAgent.match(/MSIE/));

But to use this in the conditional baffles me.

EDIT: forget about the fact that I want to use php in there somewhere.

morne
  • 4,035
  • 9
  • 50
  • 96

1 Answers1

1

You need to detect the browser on the server side using the HTTP-Header User-Agent, which is basically the same as the one used on the client-side when using navigator.userAgent in JavaScript.

I'm not a php expert, but it should work somehow like this:

<?php
  $userAgent = $_SERVER['HTTP_USER_AGENT'];
  if(preg_match('/Trident/', $userAgent) ) {
    ...
  }
?>
MattDiMu
  • 4,873
  • 1
  • 19
  • 29
  • "Conditional Comments only work in Internet Explorer on the client side" — They don't work in IE11 and the question doesn't mention them. – Quentin Sep 29 '17 at 13:26
  • @Quentin you're right, i was somehow reminded of conditional comments because of the word "conditional" and the the peusdo code :) – MattDiMu Sep 29 '17 at 13:30
  • 1
    Did not know you could get the user browser from php, Thanks mate. – morne Sep 29 '17 at 13:47