Ma********@emai l.com (Matt Adams) writes:
As well known I could specify the text color in the body tag like:
<BODY TEXT=WHITE LINK=WHITE VLINK=RED ALINK=WHITE>
As also well known, you should't, and should instead use CSS:
<style type="text/css">
body {color:white;}
:link {color:white;}
:visited {color:red;}
:visited:active {color:white}
</style>
What I want to achieve now is that always (!) the text of the last
visited link and the text of the link under the cursor are red. All
other links should be white.
The one under the cursor can be done in CSS too:
<style type="text/css">
body {color:white;}
:link, :visited {color:white;}
:link:hover, :visited:hover {color:red;}
</style>
(or, if by "the one under the cursor" you mean the one you are pressing,
not just the one you are hoovering above, then change ":hover" to ":active").
The problem is to color only one of the previously used links.
The problem with the construction above is that a visited link
remains for the rest of the session red regardless wether it was
visited 17 clicks back in the history or even just before.
I wanted ONLY the LAST visited link in red and - additionally -
the current link under the cursor (while the user chooses another link).
Probably I need a Javascript function.
You do.
I assume that your links have a target attribute, so the page itself isn't
changed (otherwise it makes no sense :).
Try this script:
---
<script type="text/javascript">
var lastClickedLink = null;
function rememberLink() {
if (lastClickedLin k) {lastClickedLin k.style.color = "";}
lastClickedLink = this;
this.style.colo r = "red";
}
function makeMemory() {
for (var i=0; i<document.link s.length; i++) {
var link = document.links[i];
if (link.addEventL istener) {
link.addEventLi stener("click", rememberLink,fa lse);
} else if (link.attachEve nt) {
link.attachEven t("onclick",rem emberLink);
} else {
link.onclick=re memberLink;
}
}
}
<script>
---
It adds an onclick event handler to all links on the page,
and when one is clicked, it changes the color of the previous one
to default, remembers the currently clicked link, and makes it red.
You call the function from, e.g., the body onload event, so it is
called when all links have been loaded.
---
<body onload="makeMem ory()">
---
Good luck.
Followup-To set to comp.lang.javas cript.
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'