0

Let's say I have a site with multiple links as follows:

www.example.com/product/1
www.example.com/product/2
www.example.com/product/3

I also append tracking info to links from time to time so that I can see how my site is being used, e.g, if somebody visits the products page from the product browser I would set a ref parameter:

www.example.com/product/1&ref=pb
www.example.com/product/2&ref=pb
www.example.com/product/3&ref=pb

The problem with this is that if the user visits a link of the first type and then views a link of the second type then the :visited pseudo class doesn't seem to apply because the browser only seems to match on exact URLs. Is there any way to have "wildcards" apply to links in this sense, so that when the user sees either the first type or the second type of link that it is highlighted?

Note: I cannot change this "ref" architecture; it is inherited.

4

3 回答 3

2

你也许可以用 javascript 做到这一点。您可以按如下方式对链接进行编码

<a href="www.example.com/product/1" onclick="document.location.href='www.example.com/product/1&ref=ab';return false;">

对于启用了 javascript 的任何人,您将看到访问 www.example.com/product/1&ref=ab,并且他们的浏览器会将所有带有 href=www.example.com/product/1 的链接检测为同一链接。并根据 :Visited 伪类适当地设置它们的样式。唯一的缺点是你不会得到那些没有 Javascript 的参考信息。这是否是一个可接受的权衡取决于您的要求。

您还可以执行以下操作:

<a href="www.example.com/product/1" onclick="document.location.href=this.href + '&ref=ab';return false;">

因此您不必在其中对 url 进行两次编码。您甚至可以创建一个返回正确链接的函数,从一个地方获取 ref 值。

于 2010-03-21T17:52:02.547 回答
0

我很确定答案是否定的。

于 2010-03-21T17:14:49.040 回答
0

如果 URL 变化甚至一个字符,它就不是同一个 URL。所以不行。

于 2010-03-21T17:37:22.540 回答