最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Disable javascript on mobile websites - Stack Overflow

programmeradmin0浏览0评论

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) ? '/'
            : '/');
    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>

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./clickdesk-ui/browser/'
            : 'http://my.clickdesk./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>
Share Improve this question asked Aug 1, 2013 at 22:22 DD.DD. 22.1k54 gold badges163 silver badges250 bronze badges 2
  • Possible duplicate: stackoverflow./questions/11381673/… – Jackson Ray Hamilton Commented Aug 1, 2013 at 22:28
  • After detecting if on a mobile device: if (!mobile) { /* chat client */ } – Jackson Ray Hamilton Commented Aug 1, 2013 at 22:29
Add a ment  | 

2 Answers 2

Reset to default 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 */
    }

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
}
发布评论

评论列表(0)

  1. 暂无评论