使用javascript将链接标记为已访问 [英] using javascript to mark a link as visited
问题描述
FF2(至少)未标记为链接为:visited如果它触发onclick处理程序而不遵循href。我使用onclick从服务器获取数据,并修改页面和链接样式在这里似乎是适当的。但该链接未标记为已访问。
FF2 (at least) doesn't mark as link as :visited if it triggers the onclick handler without following the href. I'm using onclick to fetch data from a server and modify the page and the link styling seems appropriate here. But the link is not marked as visited.
是否有跨浏览器方式将链接标记为已访问?没有,是否有一种方法来确定浏览器的a:访问的样式并将其应用于链接?
Is there a cross-browser way to mark the link as visited? Failing that, is there a way to determine the browser's a:visited styling and apply it to the link?
感谢所有回复。
Thanks to all who replied.
看起来像答案是:
- 是否有跨浏览器方式将链接标记为已访问?
否,没有办法。如果href在浏览器历史记录中,则链接被标识为已访问。
- 有没有办法确定浏览器的a:访问样式?
不,不是通过单独的javascript。
- Is there a cross-browser way to mark the link as visited?
No, there's no way to do this. Links are identified as visited if the href is in the browser history. - Is there a way to determine the browser's a:visited styling?
No, not via javascript alone.
推荐答案
这是我怎么做的。仅适用于支持HTML5历史记录API的浏览器。
Here is how I did it. Only works in browsers that support HTML5 history api.
# store the current URL
current_url = window.location.href
# use replaceState to push a new entry into the browser's history
history.replaceState({},"",desired_url)
# use replaceState again to reset the URL
history.replaceState({},"",current_url)
使用replaceState意味着后退按钮不会受到影响。
Using replaceState means that the back button won't be affected.
这篇关于使用javascript将链接标记为已访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!