Answer the question
In order to leave comments, you need to log in
How to prevent the display of a function on mobile devices?
Essence of the question: We installed a feedback widget from copyny.com
on the site Now the widget is displayed on the site and on mobile devices, The site is on WordPress https://incleanroom.ru
And we need the widget to be displayed from the side only on the site, and on mobile devices was not displayed
Tech support said I quote "But this is Javascript. You can write or take from somewhere the code for determining that the user is using mobile and, accordingly, do not call this function"
Here is the widget code:
<script type="text/javascript" charset="utf-8">
var proto = (document.location.protocol=='https:')?'https:':'http:';
var host = proto+'//widget.copiny.com';
document.write(unescape("%3Cscript src='" + host + "/static/js/newwidget.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript" charset="utf-8">
var copinyWidgetOptions = {
position: 'left',
color: '#1ba05c',
border: '#ffffff',
round: '0',
title: "\u0421\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438",
cache: "bf3b0dc169b4c5c175567223c5b2f69c\/bf3b0dc169b4c5c175567223c5b2f69c\/ejOwVXUxUHU0BJFOrkgkUMRQ1cISzDYFsyEiRmARCOmqDabckLSZIJEQbQZgthmYdASTFmqGtjmpaSUA",
positionMobile :'right',
colorMobile :'#1ba05c',
textMobile :"",
type: 'question',
community:13199
};
initCopinyWidget(copinyWidgetOptions);
CopinyNewWidget.showTab();
</script>
Answer the question
In order to leave comments, you need to log in
like this
function detectmob() {
if( navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)
){
return true;
}
else {
return false;
}
}
if(!detectmob()){
//showtab widget
initCopinyWidget(copinyWidgetOptions);
CopinyNewWidget.showTab();
}
Yes, yes, look for a list of detects that the device is mobile and do not bathe. As a last resort, the simplest solution is to go for the width... mobiles, although they have 1980+px width there, actually come out 320+ <998. So all mob devices + cut windows will fall under the cat (and you can also add a check for a miscalculation to make a decision on the resize, and you can also do it all on the server side and not let the extra script load at all).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question