IOS / Android Detection and Redirection

New to js, ​​so I'm slow: D You need to do a redirect based on what the user is using. If ios is redirected to x, if android is redirected to y, else..stay to the source address. My question is:

Are these fragments enough?

<script type="text/javascript"> // <![CDATA[ if ( (navigator.userAgent.indexOf('Android') != -1) ) { document.location = "y"; } // ]]> </script> <script type="text/javascript"> // <![CDATA[ if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) { document.location = "x"; } // ]]> </script> 

Thanks !: D

+4
source share
1 answer
 var isMobile = { Android: function() { return navigator.userAgent.match(/Android/i); }, BlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i); }, iOS: function() { return navigator.userAgent.match(/iPhone|iPad|iPod/i); }, Opera: function() { return navigator.userAgent.match(/Opera Mini/i); }, Windows: function() { return navigator.userAgent.match(/IEMobile/i); }, any: function() { return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows()); } }; if ( isMobile.Android() ) { document.location.href = "y"; } else if(isMobile.iOS()) { document.location.href="x"; } 
+21
source

Source: https://habr.com/ru/post/1490230/


All Articles