javascript 检查是否有移动设备

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 检查是否有移动设备相关的知识,希望对你有一定的参考价值。

function isMobile() {
            if (navigator.userAgent.match(/Mobi/)) {
                return true;
            }
            
            if ('screen' in window && window.screen.width < 1366) {
                return true;
            }
            
            var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
            if (connection && connection.type === 'cellular') {
                return true;
            }
            
            return false;
        }

以上是关于javascript 检查是否有移动设备的主要内容,如果未能解决你的问题,请参考以下文章