How to detect if a user is running IE 6?

你说的曾经没有我的故事 提交于 2019-12-07 12:03:27

问题


I need to be able to tell if a page is being viewed in IE 6. How can I do this in javascript while ignoring version like 7, 8, or other browsers?


回答1:


straight from the horse's mouth (and one googling away):

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;
}



回答2:


You could use conditional comments.



来源:https://stackoverflow.com/questions/917252/how-to-detect-if-a-user-is-running-ie-6

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