我可以在“通配符”上使用 CSS :visited 伪类吗?链接?
假设我有一个包含多个链接的网站,如下所示:
www.example.com/product/1
www.example.com/product/2
www.example.com/product/3
我还会不时将跟踪信息附加到链接中,以便我可以了解我的网站的使用情况,例如,如果有人从我设置的产品浏览器访问产品页面ref 参数:
www.example.com/product/1&ref=pb
www.example.com/product/2&ref=pb
www.example.com/product/3&ref=pb
这样做的问题是,如果用户访问第一种类型的链接,然后查看第二种类型的链接,则 :visited 伪类似乎不适用,因为浏览器似乎只匹配精确的网址。有没有办法让“通配符”应用于这种意义上的链接,以便当用户看到第一种类型或第二种类型的链接时它会突出显示?
注意:我无法更改此“ref”架构;它是遗传的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您也许可以使用 javascript 来完成此操作。您可以按如下方式对链接进行编码
对于启用了 javascript 的任何人,您将看到访问 www.example.com/product/1&ref=ab,并且他们的浏览器将检测到所有带有 href=www.example.com/product 的链接/1 作为相同的链接。并根据 :Visited 伪类适当地设置它们的样式。唯一的缺点是您无法获得那些没有 Javascript 的人的参考信息。这是否是一个可以接受的权衡取决于您的要求。
您还可以执行以下操作:
这样您就不必在其中对网址进行两次编码。您甚至可以创建一个返回正确链接的函数,从单个位置获取 ref 值。
You might be able to do this with javascript. You could code your links as follows
For anybody with a javascript enabled, you will see the visiting www.example.com/product/1&ref=ab, and their browser will detect all links with href=www.example.com/product/1 as the same link. And style them appropriately according to the :Visited pseudoclass. The only downside is that you won't get ref information for those without Javascript. Whether or not that's an accetable tradeoff depends on your requirements.
You could also do something like:
so you don't have to code the url in there twice. You could probably even create a function return the proper link, picking up the ref value from a single place.
我很确定答案是“不”。
I'm pretty sure the answer is 'no'.
如果 URL 哪怕只有一个字符不同,那么它就不是同一个 URL。所以...不。
If the URL varies by even one character it's not the same URL. So ... no.