背景
现代浏览器取消了经典的状态栏,而是在其窗口底部绘制了一个小工具提示,显示悬停/焦点上的链接目标。
以下屏幕截图说明了这种(在我的情况下是不受欢迎的)行为的示例:
问题
- 是否有一种可移植的方式来禁用这些工具提示?
- 在我的特定情况下,我是否遗漏了这样做的任何明显缺点?
- 我的尝试(见下文)是实现这一目标的合理方式吗?
推理
我正在开发一个 Intranet Web 应用程序,并且希望对某些特定于应用程序的操作禁用此行为,因为坦率地说,https://server/#
任何地方看起来都让人眼花缭乱,而且在某些情况下我的应用程序会在该位置绘制自己的状态栏。
我的尝试
我不是专业的网络开发人员,所以我在这个领域的知识仍然相当有限。
无论如何,这是我对 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()
用一个元素替换所有包含#
(即,在我的情况下是特定于应用程序的操作)的span
链接,使所有“外部”链接在新选项卡/窗口中打开,并且似乎不会破坏自定义协议处理。