Disabling browser tooltips on links and s

前端 未结 8 2268
误落风尘
误落风尘 2020-11-29 06:55

I want to suppress the web browser\'s default tooltip display when a user hovers over certain links and elements. I know it\'s possible but I don\'t know how. Can anyone he

8条回答
  •  天涯浪人
    2020-11-29 07:28

    As far as I know it is not possible to actually suppress showing the title tag.

    There are some workarounds however.

    Assuming you mean you want to preserve the title property on your links and elements, you could use Javascript to remove the title property at onmouseover() and set it again at onmouseout().

    // Suppress tooltip display for links that have the classname 'suppress'
    var links = document.getElementsByTagName('a');
    for (var i = 0; i < links.length; i++) {
        if (links[i].className == 'suppress') {
            links[i]._title = links[i].title;
            links[i].onmouseover = function() { 
                this.title = '';
            }
            links[i].onmouseout = function() { 
                this.title = this._title;
            }
        }
    }
    

提交回复
热议问题