0

Is there a javascript or something to block some devices and some browsers to prevent accessing my website

Only Chrome-in-Computers users can access it

like example: www.example.com -- that can only access with Chrome Browsers in any device www.example2.com -- that can only access with Firefox Browsers in Computers and Androids

  • Detect browser https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser and then do what ever you want ... – caramba Aug 03 '17 at 07:22
  • 1
    You could be inspecting the user agent server-side and deny access. You could also do the same client-side in Javascript and redirect or do something else, but that's not going to work if someone disables their Javascript. Overall, the user agent is malleable and a 100% "protection" is impossible. – I'd rather wonder *why* you want this in the first place? – deceze Aug 03 '17 at 07:22
  • As far as I understood, you want just a specific type of devices/os can access your website, it's possible, but not secure, you can get the type of device and OS information, then restrict access or allow them to visit the website, but user agent is not the best way to do that, old browsers also might be a problem – Mohammad Kermani Aug 03 '17 at 07:22
  • You can block User Agents via this .htaccess:

    http://www.inmotionhosting.com/support/website/security/block-unwanted-users-from-your-site-using-htaccess
    –  Aug 03 '17 at 07:29

1 Answers1

0

Here how you can do with javascript code:

var isChromium = window.chrome,
    winNav = window.navigator,
    vendorName = winNav.vendor,
    isOpera = winNav.userAgent.indexOf("OPR") > -1,
    isIEedge = winNav.userAgent.indexOf("Edge") > -1,
    isIOSChrome = winNav.userAgent.match("CriOS");

if(isIOSChrome){
   console.log('is Google Chrome on IOS');
   alert('is Google Chrome on IOS');
} else if(isChromium !== null && isChromium !== undefined && vendorName === "Google Inc." && isOpera == false && isIEedge == false) {
  console.log('is Google Chrome');
  alert('is Google Chrome');
} else { 
   console.log('not Google Chrome');
   alert('not Google Chrome'); 
}
ZearaeZ
  • 899
  • 8
  • 20