tags:

views:

104

answers:

3

Hi, I have a problem with a javascript set of functions that I made.

This functions walk the entire Html page and then add the onclick event to every anchor it finds.

It do some check on the anchor href and redirect to it (using window.location.href)

My problem is that the cronology don't work properly this way, and the :visited selector don't work anymore.

How I can preserve the chronology and let the :visited selector work properly?

Regards

+3  A: 

There's no need to set location.href manually: The link will be followed properly if you don't prevent it explicitly via returning false or calling event.preventDefault() (event.returnValue = false in IE) in the onclick handler.

Christoph
It work! Thank you very much.
Andrea Di Persio
A: 

Are you tracking their visits for that session?

If so, what about a server side solution instead of using Javascript.

Each time you serve up a page request, you log that Url, Page Title, etc, into their session - That way you can keep track of where they have been.

In that regard, the :visited tags will still work and you'll have a somewhat more reliable source for page history.

Hugoware
Unfortunately is a static site so I can't use server side script.
Andrea Di Persio
A: 

Use jQuery?

$('a').live('click', function(event){
    // do something
});

As long as you don't call event.preventDefault in that function you should be fine.

defrex
Too bad we can't use jQuery! I miss it!
Andrea Di Persio