erlando
erlando

Reputation: 6756

Resetting visited status on links

Is there any way you can reset the visited status on links?

The scenario is this: On an intranet-site which naturally has a lot of links we want a link to have the status of "visited" for a set period of time only. I am therefore looking for a way to manipulate the visited status of links.

Is this doable? It should be cross-browser of course.

ETA: Client-side solutions are perfectly acceptable. Preferred even.. :-)

ETA-2: Cookies are allowed. No holds barred here :-)

Upvotes: 21

Views: 35907

Answers (10)

schonarth
schonarth

Reputation: 534

Is it enough to just format the :visited CSS property of the link so that it look as if it was never clicked?

I don't know if you want to keep track of visited links for a while or just display them the same all the time; if the latter, then a simple CSS (as below) would do.

    a, a:visited {
         color: blue;
         text-decoration: underline
    }

    a:hover, a:active {
         color: orange;
    }

Upvotes: 2

Traingamer
Traingamer

Reputation: 1423

Changing how links work will generally confuse and/or upset your users. It is a sure-fire way to lower the perceived usability of your site.

What are you really trying to accomplish?

If you have subpages in your site that change (pointing to new content) your users will figure that out. If you've got a shiny new article from two or three levels deep in your page structure, add a what's new section with a link on your main page if it's that important. (Or send an notice with a link in an email, or...)

Upvotes: 1

savetheclocktower
savetheclocktower

Reputation: 1473

So you just want to make "visited" links look different for a certain amount of time? This is easy if you bypass the browser's :visited pseudoclass and just assign a custom class name. Use cookies; they've got built-in expiration.

Set up a JavaScript handler for when you click on links. Pseudo-code:

function clickHandler(event) {
  var href = /* (figure out which anchor was clicked and get the href) */
  // (you might need to escape the href)

  setCookie(href, "visited", 5); // set cookie for 5 days
}

It'll run this function right before it follows the link.

Then, on page load, you can do something like this:

function markVisitedLinks() {
  var anchors = document.getElementsByTagName("a");

  for (var i = 0; i < anchors.length; i++) {
    if (readCookie(anchors[i].href) == "visited") {
      anchors[i].className += " visited";
    }
  }
}

Grab the setCookie and readCookie functions from QuirksMode.

Upvotes: 6

ddaa
ddaa

Reputation: 54464

Links appear as "visited" when the browser chooses to apply the :visited CSS pseudo-class.

The client-side way to reset links to the unvisited state is to (somehow) clear the browsing history. I would be very surprised to learn there is a portable way to do it. It also has unpleasant side effects such as crippling the behavior of history-sensitive smart location bars such as the one in Firefox 3.

As Drew Noakes suggested, a server-side way is to add some noise query parameters to the links, and periodically change the query parameter. This only gives a bad approximation of the behaviour you want. To get the "correct" behavior you'd need to track the history of visited pages per user server-side, so you can change the noise parameter for a specific page only after the requisite time.

All said, it's very probably a bad idea to actually try to "reset the visited status on links".

I think a better solution would be to tweak the page style so the :visited pseudo class renders the same as the :link pseudo-class. Then keep a server-side history of visited links per user, and adjust the display of links using an explicit visited class.

If you do not have the user identity handy, and do not want to require login, you can always use a random persistent cookie.

Upvotes: 9

Gene
Gene

Reputation: 1527

As the problem purely visualization you don't need to worry about somehow marking the visited links back to unvisited.

Add an onclick handler to you links that changes the link style to resemble visited state. From this handler you can eg. write the link status to a cookie.

Then you can check periodically whether there are links that should not be visible anymore and change the style back to normal.

Upvotes: 0

Karl Glennon
Karl Glennon

Reputation: 3210

Maintain a list of urls visited with timestamp to users session.

When the link page loads

  • flush stale urls
  • style links contained in list as visted.

Upvotes: 0

miceuz
miceuz

Reputation: 3387

i feel something smelly in the very idea.

what is the purpose of resetting link visited status? to notify that some new data is available? then maybe something more verbose like "NEW" image would be more appropriate?

on the other hand if you really need to do this - change the URL

Upvotes: 7

Oddthinking
Oddthinking

Reputation: 25282

Change the target page to accept a parameter from a query string, and to set a cookie with an appropriate lifetime to that value.

On the referring page, put some Javascript to check for the existence of the cookie.

If it doesn't exist, have the Javascript add a parameter to the URL with a large random number in it (so the browser's history won't recognise it.)

If it does exist, have the Javascript add a parameter with the same value as the cookie (so the browser's history does recognise it.)

Notes:

  • I assume the target of the link is on the same domain as the referring page. If not, use a redirection page on the same domain.

  • This will only work if the browser's history is as long as your cookie's life. If have a short or no browser history, the client won't display it as visited.

  • Please don't do this! Your users have a good understanding of what "visited" means. don't break it - you will only confuse them.

  • Do you need to consider server-side solutions for people who don't run Javascript?

  • I have not tested this design.

Upvotes: 0

Serg
Serg

Reputation: 2946

If a simple server side solution with "changing urls", like:

"http://url1?expire2008_10_20" that becomes "http://url1?expire2008_10_21" after 24 hours,

is not ok, you can use the following:

Let the server store a cookie on a browser with the last visited time of the link. If there would be a lot of links and maximum cookie length would not be enough, you can

  1. store a session cookie and keep visited data on the server
  2. use flash analogue of cookies - Local Shared Object

Also place a code that randomizes the url for the client if the last visited time is expired.

Upvotes: 4

Drew Noakes
Drew Noakes

Reputation: 310897

I believe this is a property of the browser, and so not controllable from the server's side.

One 'hack' might be to append an unused query string on the end of links, and rotate them periodically. Although this means that the length of the 'visited' state for a particular client depends upon when the query string rotates rather than a fixed period of time.

Upvotes: 2

Related Questions