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>
DD.
  • 21,498
  • 52
  • 157
  • 246

2 Answers2

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 */
    }
CarlosO
  • 334
  • 2
  • 5
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
}
Chuncho
  • 36
  • 3