js判断是否为IE浏览器,是返回true,否返回false
function isIEBrowser(){ var Sys = {}; var ua = navigator.userAgent.toLowerCase(); var s; (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] : (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] : (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] : (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0; if(Sys.ie){ return true; } else { return false; } //if (Sys.firefox || Sys.chrome || Sys.opera || Sys.safari){ //} }
如何调用?看下面,防不住firefox -。-!
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %> <html> <head> <title>login</title> <script src="js/auth/commons.js"></script> </head> <body> <script type="text/javascript" src="<ctp:out name='fullPath'/>js/jquery-1.4.3.js"></script> <script> if(isIEBrowser()){ }else { alert("为了有更好的兼容性,请使用IE访问!"); window.self.opener = window.self; window.open('','_self'); window.self.close(); } </script> <script type="text/javascript"> </script> </body> </html>