js is a simple way to judge mobile terminal systems

  • 2021-01-06 00:28:52
  • OfStack

This article illustrates js's simple method of judging mobile terminal systems. To share with you for your reference, as follows:


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" >
<meta name="format-detection" content="telephone=no">
<title>Document</title>
</head>
<body>
<script>
  var isMobile = {
    Android : function() {
      return navigator.userAgent.match(/Android/i) ? true : false;
    },
    BlackBerry : function() {
      return navigator.userAgent.match(/BlackBerry/i) ? true : false;
    },
    iOS : function() {
      return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;
    },
    Windows : function() {
      return navigator.userAgent.match(/IEMobile/i) ? true : false;
    },
    any : function() {
      return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
    }
  };
  if (isMobile.iOS()) {
    alert("apple"); 
  } else {
    alert("Android");
  }
</script>
</body>
</html>

More about JavaScript related content interested readers can view the site features: "JavaScript search algorithm skills summary", "JavaScript animation effects and skills summary", "JavaScript error and debugging skills summary", "JavaScript data structure and algorithm skills summary", "JavaScript eraser algorithm and skills summary" and "JavaScript mathematical operation usage summary"

I hope this article is helpful to JavaScript program design.


Related articles: