Question

I have no intention of just altering the link (I hear that's impossible, but if it's not I'd love to know how). I'm fine with adding it to the the browser history if that needs to be done.

I'd like to loop through all <a>'s on a page and change their state to visited. For example:

$("a").each(function(){
   //mark as visited (somehow?)
});

Essentially creating a "Mark All as Read" button on my page. Any ideas?

Was it helpful?

Solution

You could ...

1) Try using AJAX (ie. $.get(a.href)), but I don't know if that would actually work.

2) Try styling the links to look visited (by changing their CSS "color" attribute), although this approach won't actually make them in to visited links

3) If neither of those work, you could try doing something like:

3A) Create a hidden IFRAME on the page

3B) Add a target attribute to every A tag on the page to make them point to the hidden IFRAME

3C) Invoke $("a").click() inside that each loop (possibly with a delay of some sort between each one to give the page time to load)

If none of those work, I think you're out of luck.

OTHER TIPS

Create a link that is visited (i.e. set its href to window.location), and set each of your target links' styles to that newly created link's computed style.

It's not really possible in the way you want however you could copy the CSS attributes of a:visited to a new class called "visited" or whatever then apply them to the links you want.

$('a').addClass('visited');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top