2013-08-01 42 views
1

我在我的網站上有一個聊天窗口小部件,它佔用了手機上的整個屏幕。在移動網站上禁用javascript

如何禁用具有一定寬度(或在手機上)的設備上的聊天設備?

<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> 
+0

可能重複:http://stackoverflow.com/questions/11381673/javascript - 解決方案 - 檢測 - 手機瀏覽器 – Jackson

+0

檢測後,如果在移動設備上:if(!mobile){/ *聊天客戶端* /} – Jackson

回答

1

我可能會傾向於在通過窗口大小限制,而不是設備。

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

然後

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

好的答案,+1。 – Brian

2

我已經使用這個代碼之前,它工作得很好:

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 */ 
    }