Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

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.

Looks like the answers are:

  • 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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
580 views
Welcome To Ask or Share your Answers For Others

1 Answer

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)

Using replaceState means that the back button won't be affected.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...