javascript 是否可以在悬停时隐藏链接地址?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21452543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 20:56:38  来源:igfitidea点击:

Is it possible to hide link address on hover?

javascripthtmlcsshyperlinkhover

提问by SaturnsEye

I have set up a chart with a lot of links and it really bugs me when it shows where the link goes in the bottom left hand side of the browser whenever you hover on a link, like so:

我已经设置了一个包含很多链接的图表,当您将鼠标悬停在链接上时,当它显示链接在浏览器左下角的位置时,它真的让我感到烦恼,如下所示:

enter image description here

在此处输入图片说明

Is it possible to remove this? any method will do as long as I can hide/remove it (HTML, CSS, JS etc..)

这个可以去掉吗?只要我可以隐藏/删除它,任何方法都可以(HTML、CSS、JS 等)

回答by Jakub Konecki

The status bar highlighting happens only when you use an <a>element with a set href.

状态栏突出显示仅在您使用<a>带有 set的元素时发生href

If you use pure JavaScript to open your link, and don't assign a hrefattribute, nothing will turn up in the status bar. I don't know how much control you have over the chart html, but if it renders <a>tags there's not much you can do.

如果您使用纯 JavaScript 打开链接,并且不分配href属性,则状态栏中将不会显示任何内容。我不知道你对图表 html 有多少控制,但如果它呈现<a>标签,你就无能为力了。

You could try running javascript after the chart is renderred to attach onclickevent handlers manually to all <a>tags and set href = '#'.

您可以尝试在渲染图表后运行 javascript 以将onclick事件处理程序手动附加到所有<a>标签并设置href = '#'.

回答by Thibaut Selingue

As said here: how can url be hidden in hyperlink when mouse hover

如此处所述:鼠标悬停时如何将 url 隐藏在超链接中

Don't put the URL in the href (or keep it href="#") and attach a JavaScript function to the onclick event which puts the actual link in the a element. This way you won't see the actual URL when hovering over the link but the link will be inserted when the user actually clicks.

不要将 URL 放在 href 中(或保留它 href="#")并将 JavaScript 函数附加到 onclick 事件,该函数将实际链接放在 a 元素中。这样,当鼠标悬停在链接上时,您将看不到实际的 URL,但当用户实际点击时,该链接将被插入。

回答by Okomikeruko

I had a similar problem that led me to this thread. I figured I'd post my solution here rather than start a new thread about it.

我有一个类似的问题,导致我到这个线程。我想我会在这里发布我的解决方案,而不是开始一个关于它的新线程。

I have a WordPress site with complex menus, and those menus had subheadings which the theme rendered as <a>links with empty href values. The site manager didn't want the bottom corner to display as a link if those were hovered over, since they didn't work has a link anyway.

我有一个带有复杂菜单的 WordPress 网站,这些菜单有副标题,主题呈现为<a>带有空 href 值的链接。站点管理员不希望将鼠标悬停在底角上时显示为链接,因为无论如何它们都不起作用。

<a href="#" class=" no_link" style="cursor: default;" onclick="Javascript: return false;">

I tried removing the "#" under hrefbut it still showed the site's root url on hover.

我尝试删除下面的“#”,href但它仍然在悬停时显示网站的根网址。

Since the anchor tag's class list already included no_linkas a class, I simply added the following jQuery to the global JavaScript file:

由于锚标记的类列表已no_link作为类包含在内,我只需将以下 jQuery 添加到全局 JavaScript 文件中:

$("a.no_link").removeAttr("href"); 

Note that the intention was to simply remove a link's address on hover if it wasn't supposed to be a functional link anyway.

请注意,如果无论如何都不应该是功能链接,则目的是在悬停时简单地删除链接的地址。

回答by user1428716

Refer this link here :

请在此处参考此链接:

 http://www.experts-exchange.com/Web_Development/Miscellaneous/Q_21278295.html

However , if the chart is not under your control, then this may not nbe the way

但是,如果图表不在您的控制之下,那么这可能不是方式

As suggested in the link :

正如链接中所建议的:

<a href="www.google.com" onMouseOver="window.status=' '; return true;">Pink Floyd</a>

You can also use jQuery to bind the mouseover event on these anchor links without editing individual <a>

您还可以使用 jQuery 在这些锚链接上绑定鼠标悬停事件,而无需编辑单个 <a>