简体   繁体   中英

Lost chronology using window.location.href

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

无需手动设置location.href :如果您没有通过在onclick处理程序中返回false或调用event.preventDefault() (在IE中为event.returnValue = false event.preventDefault()来明确阻止链接,则可以正确地链接。

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM