zoukankan      html  css  js  c++  java
  • js判断是否为手机或是pc

    $(function(){
      var mobile_flag = isMobile(); // true为PC端,false为手机端
    
      if(mobile_flag){
          $("#fh5co-main").css({"width": "100%", "float": "right"});
          $("#trademark").css({"margin-left": "48px","margin-top": "16px"});
      }
      console.log(mobile_flag);
    });
    
    function isMobile() {
      var userAgentInfo = navigator.userAgent;
    
      var mobileAgents = [ "Android", "iPhone", "SymbianOS", "Windows Phone", "iPad","iPod"];
    
      var mobile_flag = false;
    
      //根据userAgent判断是否是手机
      for (var v = 0; v < mobileAgents.length; v++) {
          if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
              mobile_flag = true;
              break;
          }
      }
    
       var screen_width = window.screen.width;
       var screen_height = window.screen.height;    
    
       //根据屏幕分辨率判断是否是手机
       if(screen_width < 500 && screen_height < 800){
           mobile_flag = true;
       }
    
       return mobile_flag;
    }
    

      

  • 相关阅读:
    文件上传
    使用servlet+jdbc+MD5实现用户加密登录
    JDBC入门
    springmvc(三)
    springmvc(二)
    springmvc(一)
    JavaScript总结(一)
    Spring的AOP面向切面编程
    Spring框架(三)
    Spring框架(二)
  • 原文地址:https://www.cnblogs.com/JamyWong/p/12522109.html
Copyright © 2011-2022 走看看