问题
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!
回答1:
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;
来源:https://stackoverflow.com/questions/24581233/use-jquery-to-detect-ie-then-redirect