SlimeWeb
SlimeWeb

Reputation: 33

How do I hide the content of the site only for Android devices?

Is there any way to hide the site only for android devices?
Maybe there is an option to redirect android users to a separate page?
Thanks.

Upvotes: 0

Views: 88

Answers (1)

the_previ
the_previ

Reputation: 682

You can firstly check the user agent to distinguish Android devices.

 const userAgent = navigator.userAgent || navigator.vendor || window.opera;

If is an Android device do the redirect

 if (/android/i.test(userAgent)) {
   window.location.href = "http://www.google.com";
 }

Wrap all the code in the page load function

window.onload = function() {
   const userAgent = navigator.userAgent || navigator.vendor || window.opera;
   if (/android/i.test(userAgent)) {
     window.location.href = "http://www.google.com";
   }
};

Upvotes: 4

Related Questions