473,513 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change text color of "visited link" back to unvisited color ???

As well known I could specify the text color in the body tag like:

<BODY TEXT=WHITE LINK=WHITE VLINK=RED ALINK=WHITE>

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 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.

Could someone help me ?

cu
Matt

Jul 20 '05 #1
3 17067
Ma********@email.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 (lastClickedLink) {lastClickedLink.style.color = "";}
lastClickedLink = this;
this.style.color = "red";
}
function makeMemory() {
for (var i=0; i<document.links.length; i++) {
var link = document.links[i];
if (link.addEventListener) {
link.addEventListener("click",rememberLink,false);
} else if (link.attachEvent) {
link.attachEvent("onclick",rememberLink);
} else {
link.onclick=rememberLink;
}
}
}
<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="makeMemory()">
---

Good luck.

Followup-To set to comp.lang.javascript.
/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.'
Jul 20 '05 #2
On 26 Aug 2003 12:53:40 +0200, Lasse Reichstein Nielsen
<lr*@hotpop.com> wrote:
Ma********@email.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>


I'm getting confused again.
It seems like everyone here is all about html, but when someone asks
how to do something (not just this but, seemingly everything) they are
advised to use CSS ... and then when someone asks how to do something
using CSS, they are chastised for posting to an html group (hi Jukka).
As far as the above goes, you are saying absolutely NOT to use the
html to define text and link colours but to use CSS. Cannot both be
done, as a safeguard for those browsers that don't acknowledge CSS? Or
am I reaching too far back? Don't browsers take the CSS as priority
over any html? Or is that just IE that does that?
I apologize if this sounds like I'm trying to start a fight - I'm only
asking a question that I would truly like to know the answer to.
Thanks!
Jul 20 '05 #3
Jane Withnolastname <Ja**********************@yahoo.com> writes:
I'm getting confused again.
It seems like everyone here is all about html,
Well, I'm in comp.lang.javascript, so I am not usually all about HTML
(in this group :).
but when someone asks how to do something (not just this but,
seemingly everything) they are advised to use CSS ...
Anything related to how a document is displayed, should be done with
CSS. That kind of questions probably happen a lot, especially for
people used to using HTML to do the layout.

It makes sense to use the same group for both HTML and CSS, but if
traffic is high, it has to be split in some way.
and then when someone asks how to do something using CSS, they are
chastised for posting to an html group (hi Jukka).
Chastising people is a bad idea. Referring them to another group is
good. That is what the Followup-To header is for. Discussions do
change subject over time, and when they do, they should be guided to a
more relevant group, if such exists.
As far as the above goes, you are saying absolutely NOT to use the
html to define text and link colours but to use CSS.
I wouldn't.
Cannot both be done, as a safeguard for those browsers that don't
acknowledge CSS? Or am I reaching too far back?
I think you are. Even Netscape 4 will support the simple styles
needed here.
Don't browsers take the CSS as priority over any html? Or is that
just IE that does that?
They should. That is what the CSS specification mandates.
I apologize if this sounds like I'm trying to start a fight - I'm
only asking a question that I would truly like to know the answer
to.


Doesn't sound like that to me. However, this discussion is off-topic
for comp.lang.javascript, and I am not absolutely sure where to send
it, so I'll cross-post and set Followup-To to
comp.infosystems.www.authoring.html, even though I don't read it.

I had set Followup-To in my previous post to comp.lang.javascript,
because I expected questions to the javascript part, not the CSS :)

/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.'
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
52339
by: Matt Adams | last post by:
As well known I could specify the text color in the body tag like: <BODY TEXT=WHITE LINK=WHITE VLINK=RED ALINK=WHITE> What I want to achieve now is that always (!) the text of the last visited...
12
15303
by: jfburr | last post by:
very simple thing (I hope) I've got a css style sheet that starts like this: ______________ A:link { color: cc9933; }
2
1636
by: Dot net work | last post by:
I have a 3rd party link button control that when clicked does not retain it's visited color status on postback. (Actually, the first control on the form does, but all others do not.) When I...
8
2911
by: Chad | last post by:
Should links automatically appear in the "visited" color as defined by the user's IE settings without having to add any special coding? I have a situation where the link was not changing color...
22
4665
by: subashinicse | last post by:
hi to everybody, am new to this forum.. am working with J2ee,i have a jsp page where i have some links,i want to change the link color when it is active,and it has to turn back to original color...
8
11243
by: Jeff | last post by:
ASP.NET 2.0 I'm wondering how to set the color of a visited HyperLinkField (the link text) in a GridView?? Here is the markup of the HyperLinkField I have problems with: <asp:HyperLinkField...
3
4876
by: friday13 | last post by:
Hi, I would like to set the link's "visited" pseudo-class with javascript without clicking on the link. My goal is to update the link's color (previously set in the CSS file) to be "visited"...
2
2601
by: Garima12 | last post by:
There is htm page. In its body I am calling a class from stylesheet called TaskbarStyle(classname). Now I want to change the color of hyperlink in this page as well as their active link color. I am...
2
3985
by: ghjk | last post by:
In my php web site I have left pannel which is having links to all pages. I want to change link color or background color when clicked. How can I do that? This is my current code. Could someone help...
0
7257
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7157
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7379
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1591
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.