2

我的网站上有一个聊天小部件,它占据了手机的整个屏幕。

如何在一定宽度的设备(或手机)上禁用聊天设备?

<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>
4

2 回答 2

3

我以前使用过这段代码,它工作得很好:

 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 */
    }
于 2014-09-12T19:48:15.610 回答
2

我可能倾向于通过窗口大小而不是设备来限制。

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

接着

if(!detectmob()){
    //YOUR CHAT CODE
}
于 2013-08-01T23:11:29.323 回答