防止 Chrome 中链接点击时光标发生变化
单击 Chrome(而非 Safari 或 Firefox)中的链接会将光标从指针更改为箭头。这种行为可以预防吗?即,单击后是否仍然有指针,但光标仍悬停在链接上?
编辑:好的,我做了更多测试。首先,任何人希望光标在单击链接后保持为指针的唯一原因是该链接实际上并未加载另一个页面,而是触发了 JS 事件。
<a href="test">Test</a>
// JQuery
$("a").click(function(event) { event.preventDefault(); }
使用上面的代码,event.preventDefault(或返回 false)将允许光标在单击后保持指针状态。这足以满足大多数用途,即触发 DOM 操作和/或 AJAX 请求。
问题在于history.pushState():
<a href="test">Test</a>
// JQuery
$("a").click(function(event) {
history.pushState(arg1, arg2, url);
event.preventDefault(); return false;
}
这里指针确实变成了箭头。关于如何阻止这种情况发生有什么想法吗?
Clicking on a link in Chrome (not Safari or Firefox) changes the cursor from pointer to arrow. Can this behavior be prevented? I.e., is it possible to still have the pointer after clicking, but while the cursor is still hovering over the link?
EDIT: Okay so I've done a little more testing. First of all, the only reason anyone would want the cursor to remain as a pointer after clicking on a link is if the link does not actually load another page but rather fires a JS event instead.
<a href="test">Test</a>
// JQuery
$("a").click(function(event) { event.preventDefault(); }
With the above code, event.preventDefault (or returning false) will allow the cursor to remain a pointer after click. This will suffice for most uses, namely triggering a DOM manipulation and/or AJAX request.
The problem is with history.pushState():
<a href="test">Test</a>
// JQuery
$("a").click(function(event) {
history.pushState(arg1, arg2, url);
event.preventDefault(); return false;
}
Here the pointer DOES change to an arrow. Any ideas on how to stop that from happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这听起来像是 CSS 问题。查找如下代码:
这将影响所有链接(如
a[href]
),但仅在 WebKit 中。也许还有其他原因阻止 Safari 执行此操作。更新给出的扩展问题:
现在我们对这个问题有了更多的了解,即点击某个元素后光标会变回指针并触发 JavaScript,我想说这是一个 Chrome 错误。
请在 http://bugs.chromium.org/ 提交报告
This sounds like a CSS issue. Look for code like the following:
This will affect all links (like
a[href]
) but only in WebKit. Perhaps something else is preventing Safari from doing this.UPDATE GIVEN EXPANDED QUESTION:
Now that we know more about the problem, namely that the cursor changes back to a pointer after clicking on an element fires off a javascript, I would say that this is a Chrome bug.
Please file a report at http://bugs.chromium.org/
您可以显式设置目标元素的 CSS 以包含 --
请参阅http://www.quirksmode.org/css/cursor.html#note 如果您必须支持 IE 5.5。
You could explicitly set your target element's CSS to include --
See http://www.quirksmode.org/css/cursor.html#note if you have to support IE 5.5.
与此同时,我正在考虑这个绝望的解决方法:
In the meantime I'm thinking this desperate workaround: