views:

395

answers:

3

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?

+2  A: 

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.

machineghost
I was thinking about the $.get or $.load which i think added to the history - but that's since been fixed... i think.Unfortunately I'm looking to actually change the state not just style. I've looked around and haven't found a way of adding to browser history... although a lot of people want that to happen.Looks like the hidden iFrame is the way to go. Thanks
Brennan McEachran
A: 

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');
Ben Shelock
+2  A: 

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.

DDaviesBrackett
Pretty clever if the visual is just needed..
Mike Gleason jr Couturier