js辅助式响应

window.navigator.userAgent        //检测当前运行浏览器的设备是什么

通过navigator.userAgent.indexOf('iPhone')来获取不同的客户端版本,例如‘iPhone’,然后使用 window.resize()=function(){} 返回不同样式给客户端.


window.onresize = () => {  

           Xys()      

  }

function Xys() {            

        var userAgent = navigator.userAgent            

        var html = document.querySelector('html')            

        html.className = ''           

         if (userAgent.indexOf('iPhone') != -1) {                

                 html.classList.add('iPhone')           

         } else if (userAgent.indexOf('Android') != -1) {                

                html.classList.add('Android')            

        } else if (userAgent.indexOf("iPad") != -1) {                

                html.classList.add('iPad')            

        } else {                

                html.classList.add('pc')           

         }       

 }

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。