JavaScript 中链接日志记录的最佳实践?

发布于 2024-11-30 12:21:49 字数 256 浏览 3 评论 0原文

基本上,onclick 将仅在左键单击时触发。

大多数地方推荐 onmouseup,因为它会在左键、中键和右键单击时触发。右键当然可以过滤掉。但是,通过左键单击或中键单击从文本拖动到链接,仍然可能会从 onmouseup 生成误报。

JavaScript 中是否有更直接的方法,当且仅当跟随外部链接时才会触发?或者 onmouseup 是唯一实用的解决方案吗?

Basically, onclick will trigger exclusively on left clicks.

Most places recommend onmouseup, because it triggers on left, middle, and right clicks. The right clicks can of course be filtered out. However, it is still possible to generate false positives from onmouseup by left or middle click dragging from text to the link.

Is there a more direct way in JavaScript that will be triggered if and only if an external link is followed? Or is onmouseup the only practical solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白馒头 2024-12-07 12:21:50

您可以尝试使用window.onbeforeunload。让它调用一个执行您命令的函数。你想检测什么?

You could try something with window.onbeforeunload. Have it call a function that does your bidding. What are you wanting to detect?

日暮斜阳 2024-12-07 12:21:50

我只喜欢 onmouseup
对于onbeforeunload; Opera 不支持此方法。其余所有主流浏览器都支持它。也没有公开的规范。 onbeforeunload 是由 Microsoft IE 4 引入的,随后被其他浏览器复制。

I prefer onmouseup only.
For onbeforeunload; this method is not supported in Opera. Rest all leading browsers supports it. There is no public specification for it too. onbeforeunload was introduced by Microsoft IE 4 and has subsequently been copied by other browsers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文