有多少百分比的跟随超链接可能具有“onclick”功能? JavaScript 被忽略?

发布于 2024-08-06 21:28:15 字数 507 浏览 9 评论 0原文

据我所知,所有流行的网络浏览器都会首先执行锚链接的 onclick 属性,然后遵循 href 属性指定的路径。

这里的问题是,仅当用鼠标左键单击(无需按 ctrl 或 Shift 键来打开新选项卡或窗口)或在 tabIndex 设置为您要跟踪的链接时按键盘上的 Enter 时,才会调用 onclick 属性。

但是,除了这两种方法之外,还有许多其他方法可以访问链接。

  • Ctrl + 单击
  • shift + 单击
  • 鼠标右键 + 打开
  • 鼠标右键 + 新选项卡
  • 拖动并打开将链接放到地址栏

等等...

我的客户使用 onclick 进行转化统计。这看起来非常不可靠。

我的问题: 有多少百分比的超链接在未激活其 onclick 属性的情况下被跟踪?

所有估算均受到高度赞赏。我完全迷失了;我认为它可以是任何数字...

As far as I know all popular web browsers execute the onclick attribute of an anchor link first, then follow the path specified by the href attribute.

The problem here is that the onclick attribute only gets called when clicking with the left mousebutton (without pressing ctrl or shift for a new tab or window) or when pressing enter on your keyboard while the tabIndex is set to the link you want to follow.

But there are many other ways of following a link than just those two.

  • Ctrl + click
  • shift + click
  • rightmousebutton + open
  • rightmousebutton + new tab
  • drag & drop link to address bar

and so on...

My client uses onclick for conversion statistics. Which seems heavily unreliable.

My question:
What percentage of hyperlinks are being followed without activating their onclick attribute?

All estimates are highly appreciated. I'm completely lost; I think it can be any number...

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

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

发布评论

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

评论(4

眉目亦如画i 2024-08-13 21:28:15

除了我们这些习惯于中键单击/按住 Ctrl 单击以在新选项卡中打开链接的人之外,还有 onClick 失败的另一个主要原因:NoScript 和类似的插件仅允许 javascript 在来自白名单站点时运行。如果您的域不在我的白名单中,那么无论我如何触发链接,您的 onClick 都不会运行。

如果您想要人们访问的页面的可靠统计数据,那么只有一个可靠的来源:网络服务器日志。

这些日志可能也是跟踪人们如何在整个网站上移动的最佳选择,但它们并不完全可靠,因为一些隐私偏执的用户会伪造他们的引用标头或根本不发送它们,但我希望这会是比禁用 JavaScript 更不常见。

Aside from those of us who habitually middle-click/ctrl-click to open links in new tabs, there's another major cause of onClick failure: NoScript and similar plugins which allow javascript to run only when it comes from whitelisted sites. If your domain isn't on my whitelist, then your onClick won't run, no matter how I trigger the link.

If you want reliable stats on which pages people are visiting, there's only one bulletproof source for that: The web server logs.

The logs are probably also your best bet for tracking how people move throughout the site, but they're not entirely reliable, as some privacy-paranoid users will falsify their referer headers or just not send them at all, but I expect that to be far less common than disabling javascript.

娇妻 2024-08-13 21:28:15

这取决于。如果观众更倾向于技术性,我认为使用其他方式跟踪链接会更常见。但总而言之,即使是很多技术人员似乎也不知道单击鼠标中键来打开或关闭选项卡之类的事情。如果技术人员的情况如此,那么如果普通观众中几乎没有人使用它,我也不会感到惊讶。

It depends. If the audience is more technically inclined, I'd assume that using alternative ways of following a link would be more common. All in all, though, even a lot of technical people seem to be unaware of things like clicking the middle mouse button to open or close a tab. If that's the case with technical people, I wouldn't be surprised if almost no one in the general audience used it.

゛清羽墨安 2024-08-13 21:28:15

这些链接都是退出链接。我正在考虑一个 PHP 脚本来计算点击次数。

虽然这不是您问题的主题,但您可能想看看 Google Analytics。他们是追踪你的大师。他们跟踪右键单击(即使之后没有实际选择“在新窗口中打开”,他们显然无法知道这一点),这将产生对 http://www.google.com/url

要查看正在运行的 Analytics:禁用 Adblock 等类似功能,请在 google.com 上搜索某些内容并打开 Firefox 中的实时 HTTP 标头(或 Firefox 中的 Firebug Net 选项卡,或 Safari 或 Chrome 中的 WebKit 资源窗格,按时间排序)。接下来,单击、右键单击、按住 Shift 键单击或按住 Control 键单击任何搜索结果(最好是本身不需要大量 HTTP 流量的结果,或者位于浏览器缓存中的结果)。

仅当用左键单击时才会调用 onclick 属性
鼠标按钮(无需按 Ctrl 或 Shift 键即可打开新选项卡或窗口)

不完全正确。我在 JS Bin 创建了一个快速测试,以表明修改键不会影响 onclick事件。 (对于右键单击,应使用 oncontextmenu 事件。)

The links are all exit-links. I was thinking of a PHP script that does the counting of clicks.

Though this is not the subject of your question, you might want to have a look at Google Analytics then. They are The Master in tracking you. They track right-clicks (even when not actually selecting "open in new window" after that, which they obviously cannot know), which will yield Ajax calls to http://www.google.com/url.

To see Analytics in action: with Adblock and the like disabled, search something on google.com and open up Live HTTP Headers in Firefox (or your Firebug Net tab in Firefox, or WebKit's Resources pane in Safari or Chrome, sorted by time). Next, click, right-click, shift-click or control-click any search result (preferably a result that does not require a lot of HTTP traffic by itself, or is in your browser's cache).

the onclick attribute only gets called when clicking with the left
mousebutton (without pressing ctrl or shift for a new tab or window)

Not entirely true. I created a quick test at JS Bin, to show that modifier keys do not affect the onclick event. (For right-click, one should use the oncontextmenu event.)

来日方长 2024-08-13 21:28:15

您在担心无法正常工作的 onclick 处理程序中正在做什么?例如,如果您有一个指向某个页面的常规链接...并且 onclick 只是在预先确定大小的弹出窗口中打开同一页面,以方便用户在网络应用程序中...那么可能没有问题(例如 CTRL+Click)仍然打开页面,它只是在新选项卡中打开)

如果您只是尝试“记录”站点/应用程序中的每次点击出于跟踪目的,也许您可​​以改为挂钩 onmousedown/upfocus/blur 事件。

What are you doing in your onclick handler that you are worried about not working? e.g. if you have a regular link to a page... and the onclick just opens that same page in a pre-sized popup for user convenience in a web application... then there's likely no issue (e.g. CTRL+Click) still opens the page, it just gets opened in a new tab)

If you are just trying to "log" every click in the site/application for tracking purposes then maybe you can hook into the onmousedown/up or focus/blur events instead/also.

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