1

We need to re-direct a site for ie10 only - temporarilly whilst trying to fix a bizzare ajax bug that seems to happen in ie10 and below only.

Conditional statements would be ideal - ie -

<!--[if lt IE 9]>
<script type="text/javascript">
    window.location = "/home/unsupported";
</script>
<![endif]-->

but i understand support for conditional was removed from ie10 - is there a way we can redirect ie10 only?

Cheers

Dancer
  • 17,035
  • 38
  • 129
  • 206
  • Check with JS what the browser is since you are already using JS to redirect. – putvande Aug 14 '15 at 10:58
  • 2
    Instead of asking how to detect IE10, you should ask for solution on your actual problem, as it might be specific workarounds for it based on functionality not using browser-sniffing. – awe Aug 14 '15 at 11:05
  • @awe he said it is temporary redirection "temporarilly whilst trying to fix a bizzare ajax bug that seems to happen in ie10 and below only." – Develoger Aug 14 '15 at 11:12

2 Answers2

2

As you mentioned IE conditional statements are discarded after IE9: https://msdn.microsoft.com/en-us/library/hh801214%28v=vs.85%29.aspx

Detecting IE10 with JS can be tricky if you rely on the User Agent so please see this example on how to do it properly: Check for IE 10

After you detect the IE10 it is very easy to do the redirection in JS...

Community
  • 1
  • 1
Develoger
  • 3,950
  • 2
  • 24
  • 38
  • Just to add something that might help - versions of IE up through 10 have "MSIE" in their user agent string. IE11 does not. – libertyernie Aug 14 '15 at 13:06
  • Usually that is true, but my experience with UserAgent strings is that they can be so ridiculous and you just can not trust that information if you want to be very precise in detection. – Develoger Aug 14 '15 at 13:14
0

You can use the following java script to detect the browser and it's version.

var x = navigator.userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];

the x will be an array.. X[1] will contain browser and x[2] will contain the version.

for redirection you can use window.location or the followiung code if you want a post..

<script type="text/javascript">
 var f = document.createElement("form");
 f.setAttribute("action", "/userSpace");
 f.setAttribute("method", "POST");
 document.body.appendChild(f);
 setTimeout(f.submit(),3000);
</script>
Sumodh S
  • 709
  • 1
  • 14
  • 36