2

I have a chat widget on my website which takes up the whole screen on a mobile phone.

How do I disable the chat device on devices of a certain width (or on mobile phones)?

<script type="text/javascript">
    var _glc = _glc || [];
    _glc.push('all_agddsffsd');
    var glcpath = (('https:' == document.location.protocol) ? 'https://my.clickdesk.com/clickdesk-ui/browser/'
            : 'http://my.clickdesk.com/clickdesk-ui/browser/');
    var glcp = (('https:' == document.location.protocol) ? 'https://'
            : 'http://');
    var glcspt = document.createElement('script');
    glcspt.type = 'text/javascript';
    glcspt.async = true;
    glcspt.src = glcpath + 'livechat-new.js';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(glcspt, s);
</script>
2

2 Answers 2

3

I have used this code before and it works just fine:

 var isMobile = {
    Android: function() {
        return navigator.userAgent.match(/Android/i);
    },
    BlackBerry: function() {
        return navigator.userAgent.match(/BlackBerry/i);
    },
    iOS: function() {
        return navigator.userAgent.match(/iPhone|iPad|iPod/i);
    },
    Opera: function() {
        return navigator.userAgent.match(/Opera Mini/i);
    },
    Windows: function() {
        return navigator.userAgent.match(/IEMobile/i);
    },
    any: function() {
        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
    }
};
    if(!isMobile.any()) {
    /* Your Code to disable in mobile here */
    }
Sign up to request clarification or add additional context in comments.

Comments

2

I would probably incline in restricting by window size, rather than device.

function detectmob() {
   if(window.innerWidth <= 800 && window.innerHeight <= 600) {
     return true;
   } else {
     return false;
   }
}

and then

if(!detectmob()){
    //YOUR CHAT CODE
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.