使应用程序浏览器具体化

时间:2013-05-09 10:54:52

标签: java javascript jsp browser login

我的应用程序经过测试和支持的平台是基于Windows的计算机,IE为浏览器。如果用户使用的浏览器不是Internet Explorer,则我的应用程序不应允许用户登录。

我该怎么做提前致谢

1 个答案:

答案 0 :(得分:1)

好吧,如果确实想要检测IE的使用情况(尽管在大多数情况下检测浏览器支持的功能会更好),您可以检查用户代理是否是Internet Explorer,如果不是,禁用登录。

在以下Microsoft的代码段中,getInternetExplorerVersion()返回-1,浏览器不是IE,如果浏览器是IE,则返回版本。根据此功能的值,您可以决定是否启用登录。

示例

var IEdetected = getInternetExplorerVersion();
if (IEdetected == -1){
     // disable login
}

来自MSDN的IE检测代码

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
function checkVersion()
{
  var msg = "You're not using Internet Explorer.";
  var ver = getInternetExplorerVersion();

  if ( ver > -1 )
  {
    if ( ver >= 8.0 ) 
      msg = "You're using a recent copy of Internet Explorer."
    else
      msg = "You should upgrade your copy of Internet Explorer.";
  }
  alert( msg );
}

MSDN文章Detecting Windows Internet Explorer More Effectively

中的浏览器检测代码