4

I've implemented the bootstrap tooltips on a web site and they work fine on a desktop screen. But they are proving problematic for smaller devices. Clicking on a link on a small screen device without hover functionality just brings up the tooltip instead of clicking through to the link destination. Is there a way to turn off or disable tooltips for smaller devices, perhaps using some kind of check in the jquery code?

Bob Foster
  • 190
  • 1
  • 8

2 Answers2

11

You could do a check for touch events before calling the init on bootstrap tooltip. This will allow you to disable the tooltip feature for most touch devices not just smaller screen size touch devices like mobiles.

if(!('ontouchstart' in window))
{
  $('#example').tooltip(options); // <-- Example code from Bootstrap docs
}
Kyle Needham
  • 3,331
  • 2
  • 22
  • 38
  • Thanks, yes, touch devices are likely more the key factor here, not just screen size. I've not tested on an iPad but likely, even on a large pixel width screen, the problem would persist there as well. – Bob Foster Apr 13 '14 at 22:46
  • can you provide more info about the 3 'nots' '!' in your if statement? Is ontouchstart part of jquery or javascript itself? I'm trying to determine if ontouchstart would be available on all devices. – Bob Foster Apr 13 '14 at 22:49
  • @BobFoster Sorry that was just a typo, this method is supported in all modern browsers but if you want almost complete support check out [modernizr](http://modernizr.com/). – Kyle Needham Apr 14 '14 at 08:49
  • This isn't working on chrome for me (ie: this turns off hover triggered tooltips in Chrome browser on a desktop). Anyone else? – theyuv Oct 08 '16 at 11:04
  • Does this work on computers with touch screens and a mouse? If the user hovers the mouse on the element even though their monitor is a touch screen the hover should show. – Lee Aug 11 '20 at 13:59
1

Maybe something like this:

if ( $(window).width() < 780 ){
    $('#element').tooltip('destroy');
}
Miljan Puzović
  • 5,602
  • 1
  • 21
  • 29
  • thanks, this is likely the code we should use but the test used in the if statement is something I'm still thinking about. – Bob Foster Apr 13 '14 at 22:50