原生JavaScript判断是否移动设备
Posted William Shaw技术博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了原生JavaScript判断是否移动设备相关的知识,希望对你有一定的参考价值。
function isMobile(){ if (typeof this._isMobile === ‘boolean‘){ return this._isMobile; } var screenWidth = this.getScreenWidth(); var fixViewPortsExperiment = rendererModel.runningExperiments.FixViewport || rendererModel.runningExperiments.fixviewport; var fixViewPortsExperimentRunning = fixViewPortsExperiment && (fixViewPortsExperiment.toLowerCase() === "new"); if(!fixViewPortsExperiment){ if(!this.isAppleMobileDevice()){ screenWidth = screenWidth/window.devicePixelRatio; } } var isMobileScreenSize = screenWidth < 600; var isMobileUserAgent = false; this._isMobile = isMobileScreenSize && this.isTouchScreen(); return this._isMobile; }
以上是关于原生JavaScript判断是否移动设备的主要内容,如果未能解决你的问题,请参考以下文章