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
2 Answers
Reset to default 3I 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
}