A:Visited 未检测到 AJAX 链接

发布于 2024-10-21 19:53:36 字数 259 浏览 8 评论 0原文

我注意到 a:visited 样式不适用于通过 JavaScript 请求的链接。但是,在标准用户单击时,会立即和随后的刷新时注册访问的完全相同的链接。我不确定这是否是 jQuery Mobile< 所独有的/a> (我第一次遇到它的地方)或者这是否是我不知道的浏览器限制?

I'm noticing that a:visited styles don't work on links that are requested via JavaScript. On a standard user click though, the exact same link registers as visited, both immediately and on subsequent refreshes. I'm not sure if this is unique to jQuery Mobile (where I first encountered it) or whether it's a browser limitation that I didn't know about?

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

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

发布评论

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

评论(5

寄居者 2024-10-28 19:53:36

如果您希望它能够处理历史记录和访问过的链接样式,您可能需要更改 location.hash。

请记住,在基于浏览历史记录隐私漏洞的访问链接因 你看过色情吗? 网站。

You probably need to change the location.hash if you want it to work with history and visited links styling.

Keep in mind that the visited links styling works somewhat inconsistently between browser after the visited links based browsing history privacy vulnerability was made popular by Did You Watch Porn website.

厌味 2024-10-28 19:53:36

a:visited 匹配指向浏览器历史记录中 URL 的任何链接。

如果您使用 AJAX 取消导航到 URL,则该 URL 将永远不会出现在浏览器历史记录中。

您可以使用 # 链接来修复该问题。

a:visited matches any link that points to a URL that is in the browser history.

If you use AJAX to cancel navigation to the URL, the URL will never end up in the browser history.

You can fix that by using # links.

讽刺将军 2024-10-28 19:53:36

仅当链接“执行”时才会触发 a:visited

指向 AJAX 调用的链接通常返回“false”(带有哈希的解决方案 (link) 仍然返回 false,否则用户将跳转到页面顶部)。

这样,链接就永远不会被“执行”,因此不会被标记为已访问。

a:visited is only triggered if the link is 'executed'.

A link to an AJAX call usually returns 'false' (The solution with a hash (<a href="#">link</a>) still returns false otherwise the user would jump to top of page).

That way the link is never being 'executed', therefore not being marked as visited.

回眸一遍 2024-10-28 19:53:36

好的,请不要像其他回答者所说的那样将 a 元素的 href 更改为指向哈希 URL - 这会破坏用户体验。如果他们想在新窗口中打开,则需要双重加载,如果您在服务器端进行更改,则会破坏搜索引擎和禁用 js 的用户。

问题是,如果您使用哈希将网站升级为 RIA(富互联网应用程序),那么链接将指向 mysite.com/page,但您实际上访问的是 mysite.com/ #/page 因此您实际上并没有访问原始内容。

这里正确的解决方案是使用 HTML5 History API,它允许您直接更改 URL 并挂钩 URL 更改(因此不再需要哈希)。您可以在此处详细了解 hashes、hashbangs 和 HTML5 History API 的优缺点:
https://github.com/browserstate/history.js/wiki/Intelligent -State-Handling - 它还包括使用 HTML5 History API 升级您的网站的示例代码。

jQuery Mobile 计划在未来使用 HTML5 History API(目前正在开发中),但目前我建议等待它实现。

Okay, please don't change a element's href to point to a hashed url like the other answerers are saying - that will break the user experience. If they want to open in new window it will then need to double load, if you do the change server-side it will break search engines and js-disabled users.

The issue is that if you are using hashes to upgrade your website into a RIA (rich internet application) then the links will point to mysite.com/page but you actually access mysite.com/#/page so you don't actually visit the original.

The proper solution here is to use the HTML5 History API, which allows you to change the URL directly and hook into URL changes (so there is no longer a need for hashes). You can read more about the pros and cons of hashes vs hashbangs vs HTML5 History API here:
https://github.com/browserstate/history.js/wiki/Intelligent-State-Handling - it also includes sample code to upgrade your website with the HTML5 History API too.

jQuery Mobile is scheduled to use to the HTML5 History API in the future (it's currently being worked on), but for now I'd suggest waiting it this is implemented.

梦断已成空 2024-10-28 19:53:36

您始终可以通过与 a:visited 共享样式的 ajax 回调在链接上设置一个类。

You can always set a class on the link via the ajax callback that shares the style with a:visited.

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