Forum Moderators: open
My pages are dynamic and make heavy use of templates etc., so I don't want to create a separate menu for each page with just that link disabled.
I was thinking there must be a way to get my asp code to find links that point to the current page and disable them. I think a regular expression would be the way to do this, but I'm a real novice at them and don't know the syntax.
Can anyone help?
What it needs is to
At minimum: find any href="this URL" inside an <a> tag and replace "this URL" with nothing
Ideally: take out the whole <a> tag and the following </a> (in order to remove the associated formatting as well.
Can anyone help with these regular expressions? :)
<% Dim sFullPath Dim lPathLength Dim iCounter Dim ptrCharacterStart, ptrCharacterEnd Dim sCurrentCharacter, sCurrentDirectory Dim FileName, SubZone, MainZone [/code]
[code]sFullPath = Request.ServerVariables("Path_Info") [/code]
[code]'-------------------------------------------------- ' Here we just snip the leading / away. ' reduce length because we just snipped the above char. ' set where we start looking. '-------------------------------------------------- [/code]
[code]lPathLength = Len(sFullPath) sFullPath = Mid(sFullPath,2,lPathLength) lPathLength = (lPathLength -1) ptrCharacterStart = 1 [/code]
[code]'-------------------------------------------------- ' This loop is the actual script that parses the current URL. '-------------------------------------------------- [/code]
[code]For iCounter = 1 to lPathLength sCurrentCharacter = Mid(sFullPath,iCounter,1) If sCurrentCharacter = "/" Then ptrCharacterEnd = iCounter sCurrentDirectory = Mid(sFullPath,ptrCharacterStart,ptrCharacterEnd-(ptrCharacterStart-1)) ptrCharacterStart = (iCounter + 1) End If Next [/code]
[code]FileName = Right(sFullPath,(lPathLength-ptrCharacterEnd)) MainZone = Replace(sCurrentDirectory,"/","") ' Current Directory SubZone = Left(FileName,Len(FileName)-4) ' Here we just snip the 4char extension away. %> I named this file
NameLocation.inc and place it in the directory /include/ and adde to every page this line inside the heaer: <!--#include File='/include/NameLocation.inc'--> Then I go and edit my navigation, from for example:
<a href="/folder/file.asp">linktexthere</a> to
<% If MainZone = "folder" and SubZone = "file" Then %> <a href="/folder/file.asp"> <% End If %> linktexthere <% If MainZone = "folder" and SubZone = "file" Then %> </a> <% End If %> of course in that example you could discuss if the html should be outputted with a Response.Write to not mix asp and html too much (helps the readability) and all the white spaces it produces, but this way you can look at it in any WYSIWYG html editor and see what you'll get, and it'll do the trick
thanks for that but unfortunately it won't work for me.
Your code takes the route of "only ADD in link if it does not point to current page". But I need to do the reverse: "REMOVE link from HTML page (passed through code as a single string) if it points to current page".
This is because I'm using a content management system, so my menus etc. are stored as blocks of HTML in a database - I can parse them during the output process, but I can't intersperse them with ASP code in the fashion that your code does.
I should have been clearer in my original post :(
Jonathan
.currentpage
{
cursor: default;
text-decoration: none;
color: Black;
}
<a href="/thecurrentpage.asp" class="currentpage">This links to the current page</a><br>
<a href="/someotherpage.asp">This links to some other page</a>
Jakob Nielsen's point about not linking to the current page is that users get disconcerted that they click on a hyperlink and nothing happens. Well, in this case, all the visual clues are that this isn't a hyperlink, so if you click on it and nothing happens, then all is well with the world. I think I addressed his real point, without having to actually remove the hyperlink altogether, which is substantially more difficult.