Wednesday, 28 September 2016

Detect Mobile Device in JavaScript

To check the device is mobile or desktop in JavaScript, use the function given below
        function isMobile() {
            if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
                return true;
            }
            return false;
        }
    
To check the orientation of the device, check the width and height of the device.
        function isPortrait() {
            return window.innerHeight > window.innerWidth;
        }
    

No comments:

Post a Comment