简体   繁体   English

使用window.location.href丢失的年代

[英]Lost chronology using window.location.href

I have a problem with a javascript set of functions that I made. 我制作的一组javascript函数有问题。

This functions walk the entire Html page and then add the onclick event to every anchor it finds. 此函数遍历整个HTML页面,然后将onclick事件添加到它找到的每个锚点。

It do some check on the anchor href and redirect to it (using window.location.href) 它对锚href进行一些检查并重定向到它(使用window.location.href)

My problem is that the cronology don't work properly this way, and the :visited selector don't work anymore. 我的问题是,年代学无法以这种方式正常工作,并且:visited选择器不再起作用。

How I can preserve the chronology and let the :visited selector work properly? 如何保存时间顺序并让:visited选择器正常工作?

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. 如果是这样,那么如何使用服务器端解决方案而不是使用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. 每次提供页面请求时,您都将Url,Page Title等记录到他们的会话中-这样,您就可以跟踪它们的去向。

In that regard, the :visited tags will still work and you'll have a somewhat more reliable source for page history. 在这方面,:visited标记仍将起作用,并且您将获得页面历史记录更为可靠的来源。

Use jQuery ? 使用jQuery吗?

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

As long as you don't call event.preventDefault in that function you should be fine. 只要您不在该函数中调用event.preventDefault就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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