简体   繁体   English

如何使网站仅在某些浏览器中运行?

[英]How to make a website run only in certain browsers?

How to make a check on a client's browser on a website?如何在网站上检查客户端的浏览器? I was given the task that the website was supported only by Google Chrome or Firefox我的任务是该网站仅受 Google Chrome 或 Firefox 支持

When user uses other browsers, a blank page should appear with text similar to当用户使用其他浏览器时,应出现一个空白页面,其文本类似于

Your browser is not supported by the system.
Use Google Chrome or Firefox Browsers

By checking the string navigator.userAgent通过检查字符串navigator.userAgent

Check the function bellow, and adapt it to your needs.检查下面的功能,并根据您的需要进行调整。

function wichBrowser() {
  // CHROME
  if (navigator.userAgent.indexOf("Chrome") > -1 ) {
    return "Google Chrome"
  }
  // FIREFOX
  else if (navigator.userAgent.indexOf("Firefox") > -1 ) {
    return "Mozilla Firefox"
  }
  // INTERNET EXPLORER
  else if (navigator.userAgent.indexOf("MSIE") > -1 ) {
    return "Internet Exploder"
  }
  // EDGE
  else if (navigator.userAgent.indexOf("Edge") > -1 ) {
    return "Edge"
  }
  // SAFARI
  else if (navigator.userAgent.indexOf("Safari") > -1 ) {
    return "Safari"
  }
  // OPERA
  else if (navigator.userAgent.indexOf("Opera") > -1 ) {
    return "Opera"
  }
  // YANDEX BROWSER
  else if (navigator.userAgent.indexOf("Opera") > -1 ) {
    return "YaBrowser"
  }
  // OTHERS
  else {
    return "Others"
  }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM