js determine whether the user is a mobile terminal or computer terminal access

By determining userAgent, page navigation objects can be used directly

ctx.request.header end node can request header [ 'user-agent']

 

Browser = const { 
    versions (U) { 
        return {   // mobile terminal browser version information 
            Trident: u.indexOf ( 'Trident')> -1,   // IEs core 
            presto: u.indexOf ( 'Presto') > -1 ,     // Opera core 
            WebKit: u.indexOf ( 'AppleWebKit')> -1,   // Apple, Google kernel 
            gecko: u.indexOf ( 'Gecko') > -1 && u.indexOf ( 'KHTML') == - 1,   // Firefox core 
            mobile: !! u.match (. /AppleWebKit.*Mobile * /) || !! u.match (/ AppleWebKit /) && u.indexOf ( 'QIHU') && u.indexOf ( 'Chrome' ) <0,   // whether the mobile terminal 
            ios: !! u.match (/ \ (   i [^;] +; (U;)? The CPU. Mac OS the X-+ /), // iOS terminal
            Android: u.indexOf ( 'the Android')> -1 || u.indexOf ( 'the Linux')> -1,   // the Android terminal or UC browser 
            iPhone: u.indexOf ( 'iPhone') > -1 || u.indexOf ( 'the Mac')> -1,   // whether or QQHD browser iPhone 
            the iPad: u.indexOf ( 'the iPad')> -1,    // whether the iPad 
            webApp: u.indexOf ( 'Safari') = = -1,    // whether WEB program should not head to the bottom. 
            UA: U 
        } 
    } 
} 
module.exports = Browser

 

Guess you like

Origin www.cnblogs.com/php-noob-for-now/p/11115805.html