Use Jquery to detect IE, then redirect [duplicate]

十年热恋 提交于 2019-12-14 03:34:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!