Search code examples
tooltip

jQuery tooltip re-opens on window focus


I have the following problem with jQuery (1.10.3) tooltip plugin.

I have several links like

<a target="_blank" class="tooltip_top_studios">Link1</a>

and jquery code:

$(".tooltip_top_studios").tooltip({
    tooltipClass:'ui-tooltip',
    position: { my: "left+15 top", at: "right center" },
    show: { effect: "fadeIn", delay: 300},

    content: function() {
       var img_src = $(this).attr('rel');
       var html =  "<h1 style='color:#d4dce8;margin-bottom:7px;'>" 
          + $(this).attr('title') + "</h1>" + "<span style='font-weight:bold;font-size:10px;margin-bottom:7px;padding:0;display:block;'>"  
          + $(this).attr('name') + "</span><img width=280 src='" + img_src + "' /> ";

        return html;
     },
});

The problem is that when I click the link, tooltip appears without any problem and new tab with link's URLopens, but when I return to the first page tooltip appears again. I have to click somewhere in page to close it.

Maybe there is a way to close all tooltips on window focus automatically ?


Solution

  • Finally I found the solution. The problem caused because then I return on page focus on tooltip anchore was not removed automaticaly, so tooltip executed again. This code remove focus from all a tags and worked fine :

    $(window).focus(function() {
    $('a').focus(function() {
        this.blur();
    });
    
    });