背景
现代浏览器取消了传统的状态栏,而是在窗口底部绘制一个小工具提示,在鼠标悬停/聚焦时显示链接目标。
以下截图展示了这种(在我的情况下)不受欢迎的行为:
问题
- 有一种通用方法可以禁用这些工具提示吗?
- 在我的特定情况下,我是否忽略了任何明显的缺点?
- 我的尝试(见下文)是实现这一点的合理方式吗?
推理
我正在开发一个内部网站应用程序,并希望针对某些特定应用程序操作禁用此行为,因为在某些情况下,“https://server/#” 看起来很丑陋,并且由于我的应用程序在该位置绘制自己的状态栏,因此会影响使用。
我的尝试
虽然我不是专业的 Web 开发人员,但我有一些 jQuery 的知识,以下是我的尝试:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Target Tooltip Test</title>
<style>
a, span.a {
color: #F00;
cursor: pointer;
text-decoration: none;
}
a:hover, span.a:hover {
color: #00F;
}
a:focus, span.a:focus {
color: #00F;
outline: 1px dotted;
}
</style>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script>
$(document).ready(function() {
patch();
});
function patch() {
$('a').each(function() {
var $this = $(this).prop('tabindex', 0);
if($this.prop('href').indexOf('#') == -1 || $this.prop('rel').toLowerCase() == 'external') {
return;
}
var $span = $('<span class="a" tabindex="0"></span>');
$span.prop('data-href', $this.prop('href'));
$span.text($this.text());
$this.replaceWith($span);
});
$('a[rel="external"]').click(function() {
window.open($(this).prop('data-href'));
return false;
});
$('span.a').click(function() {
location.href = $(this).prop('data-href');
}).keypress(function(event) {
if(event.keyCode == 13) {
location.href = $(event.target).prop('data-href');
}
}).focus(function() {
window.status = ''; // IE9 fix.
});
}
</script>
</head>
<body>
<ol>
<li><a href="http://google.com" rel="external">External Link</a></li>
<li><a href="#foo">Action Foo</a></li>
<li><a href="#bar">Action Bar</a></li>
<li><a href="#baz">Action Baz</a></li>
<li><a href="mailto:support@example.org">Email Support</a></li>
</ol>
</body>
</html>
patch()
会用一个元素替换包含#
的所有链接(在本例中代表应用特定操作),将所有“外部”链接在新标签页或窗口中打开,并且似乎不会破坏自定义协议处理。