在导航中禁用指向当前页面的链接 [英] Disable link to the current page in navigation

查看:120
本文介绍了在导航中禁用指向当前页面的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站的漂亮的标准导航。主导航是一个ul,有几个嵌套的ul。我基本上只是想当用户已经在该页面上时动态地禁用链接。

I have a pretty standard navigation for a website. The main navigation is a ul, with several nested ul's. I'm basically just wanting to dynamically disable a link when the user is already on that page.

因此,如果我在主页上,主页链接需要被禁用。如果我在联系人页面上,则需要禁用联系人页面链接。

So if I'm on the home page, the home page link needs to be disabled. If I'm on the contact page, the contact page link needs to be disabled.

我不想完全删除链接,只需从锚点中删除href或者只是使锚本身停用。在XHTML,CSS,JavaScript或PHP中有一个快速,灵活和优雅的解决方案。我也想要一个全面友好的解决方案,而不只是现代浏览器(你可以阅读,IE 6)。

I am not wanting to delete the link entirely, just remove the href from the anchor or just make the anchor itself de-activated. Is there a fast, slick and elegant solution for this in XHTML, CSS, JavaScript or php. I'd also want a solution that's friendly across the board, not just for modern browsers (you can read, IE 6).

我想到设置一个路径变量在每个页面,然后有一个if语句为每个链接,但这似乎可怕的乏味和愚蠢。

I did think of setting a path variable on each page, and then having an if statement for each link, but that seems horribly tedious and stupid. But hey, it would get the job done.

推荐答案

我认为最好在页面生成代码中执行此操作即PHP),遍历每个链接并去除< a> 标签,将其替换为< span> 或类似的,如果链接匹配的标准匹配当前页面。 PHP给你这个当前页面(各种口味: $ _ SERVER ['REQUEST_URI'] $ _ SERVER ['SCRIPT_FILENAME'] $ _ SERVER ['PHP_SELF'] $ _ SERVER ['QUERY_STRING'] 基础,并使用这些,您可以确定一个算法来匹配您的页面。

I think it would be best to do this in the page generation code (i.e. PHP), iterating through each link and removing the <a> tag, replacing it with a <span> or something similar if the link matches the criteria for matching the current page. PHP gives you this current page (in various flavors: $_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_FILENAME'], $_SERVER['PHP_SELF'], $_SERVER['QUERY_STRING'], etc.) in its base, and using these, you can determine an algorithm to match your page.

这篇关于在导航中禁用指向当前页面的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆