-1

I've been all over stackoverflow and google trying to find a solution to this. All other stackoverflow pages seem to be a bunch of snippets and people arguing over browser/feature detection.

To start with: Yes, I am aware browser sniffing is not the most renowned solution No, I don't care right now. I plan to offer a optimized page for the IE users (Until IE decides to recognize all the code I want to use).

All I really need is a simple .js that will detect if the browser is any version of IE and then redirect them to another page.

Essentially: detect IE, if IE redirect to "IEPage"

I'd really appreciate the help, thank you very much!

mtechs
  • 21
  • 3
  • modernizr has a better approach, if the browser doesn't have the features you need, you redirect.. you'll get all ie users plus maybe some outdated firefox – enapupe Jul 04 '14 at 22:17

1 Answers1

0
var url = "http://example.com"; 
/msie|trident/i.test(navigator.userAgent) ? document.location = url : null;

Edit

Note, userAgent could be changed at client side.

Could also teststyle object, or CSSStyleDeclaration of document.body for vendor specific prefix . See Vendor-prefixed CSS Property Overview

( "msFlex" || "msAnimation" ) in document.body.style ? document.location = url : null;
guest271314
  • 1
  • 10
  • 82
  • 156
  • I had the same idea...but somehow in IE11 it seems this does not work anymore. I just tested it in the console of IE 11 (v11.0.9600.17126) and your code returned null...navigator.userAgent appears as '"Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; rv:11.0) like Gecko"' maybe this is done for compatibility reasons or just the console tells that (what i can't imagine...but there are sometimes strange effects on IE..) – L. Monty Jul 04 '14 at 22:31
  • It is for compatibility reasons. Microsoft did a lot of work to stop their browser being awful, and then people continued to block IE users because IE used to be awful, so they changed the UA to stop looking so much like old IE. (This is why the premise of the question is terrible). – Quentin Jul 04 '14 at 22:38
  • This worked after taking out `windows|` (For obvious reasons). Thanks! – mtechs Jul 04 '14 at 23:08