-1

I just launched a mobile version of my site and I’m having a hard time hiding a live chat script on the mobile hide-for-small. This is the code I don't want displayed on the mobile version:

<script src="http://www.smartreachdigitalchat.com/scripts/invitation.ashx?company=?????"></script>

All the things I don’t want displayed on the mobile I simply write:

<div class="small hide-for-small"><script src="http://www.smartreachdigitalchat.com/scripts/invitation.ashx?company=?????"></script></div>

…and it would hide from mobile devices and only display on desktop computers, but here it’s not working; it seems to be hiding from both desktop and mobile.

What can I do to make the script execute only on desktop computers?

icktoofay
  • 117,602
  • 18
  • 233
  • 223
booya1969
  • 1
  • 2

1 Answers1

1

try something like this:

<script>
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
    //Do something for mobile
    alert("MOBILE");
}else{
    var script = document.createElement('script');
    script.src = "http://www.smartreachdigitalchat.com/scripts/invitation/apexchat.js?company=2051";
    document.write(script.outerHTML);
}
</script>

It will show live chat on computer and hide on mobile device:

show on computer

hide on mobile device

He Yifei 何一非
  • 2,292
  • 3
  • 31
  • 66