views:

1568

answers:

10

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 :-)

+2  A: 

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.

Drew Noakes
+3  A: 

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.

Sergey
+2  A: 

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.

ddaa
A: 

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.

Oddthinking
+4  A: 

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

miceuz
It's an intranet. All the links will quickly become visited for any one user. Therefore the visited status loses any meaning if not reset once in a while.
erlando
then there is a question why do you need to distinguish between visited and nonvisited links? is there any real usability advantage?
miceuz
This answers it all, @erlando. If you want to reset the visited status, add something to the end of each link you want that, such as http://intranet/link#modified-2010-03-17
Cawas
A: 

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.
Recursieve
A: 

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.

Gene
+1  A: 

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.

savetheclocktower
A: 

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...)

Traingamer
A: 
schonarth