By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,156 Members | 1,069 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,156 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
9 Replies


P: n/a
Matt Adams wrote:
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.


use CSS to do this..

a {color:#fff;}
a:visited {color:#fff;}
a:active, a:hover {color:#f00;}

teh ":active" thing tells the browser to apply this style when the focus is
on the link. I think this is about as far as css will be able to help you
out.
Jul 20 '05 #2

P: n/a
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 #3

P: n/a
rf

"Matt Adams" <Ma********@email.com> wrote in message
news:bi*************@news.t-online.com...
As well known I could specify the text color in the body tag like:

<BODY TEXT=WHITE LINK=WHITE VLINK=RED ALINK=WHITE>
Hmmm. It is well known these days that such presentational things are done
with CSS.
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
Nope. See below.
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.


No. You need to rethink that you want.

The 'visited' colour is there so your viewer can see that she has been to
that particular page before. Nothing more. nothing less.

'Visited' links get 'unvisited' when your viewers history gets emptied or
expires, something over which you have no control whatsoever.

You could fudge it by looking at the referring page and colouring it's link
on the new page but would be a whole bunch of server side stuff for IMHO
little gain.

Why do you want to do this anyway?

Cheers
Richard.
Jul 20 '05 #4

P: n/a

"Matt Adams" <Ma********@email.com> wrote in message
news:bi*************@news.t-online.com...
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 ?


This is a browser function. There is no way of differenciating between a
link visited a moment ago and one 20 minute ago.A VLINK is a VLINK.
Jul 20 '05 #5

P: n/a
Matt Adams wrote:
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.


Cannot be done.

--
Toby A Inkster BSc (Hons) ARCS | mailto:to*****@goddamn.co.uk | pgp:0x6A2A7D39
aim:inka80 | icq:6622880 | yahoo:tobyink | jabber:ta*@jabber.linux.it
http://www.goddamn.co.uk/tobyink/ | "You've got spam!"
playing://(nothing)
Jul 20 '05 #6

P: n/a
In article <bi*************@news.t-online.com> in
comp.infosystems.www.authoring.html, Matt Adams
<Ma********@email.com> wrote:
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.


(1) Not the session, but the number of days specified by the user in
_her_ browser preferences.

(2) And this is a good thing, not a problem. Users like to know
which links they have visited, so that they can more easily find
them again, _or_ so that they can not waste time going back to
something unproductive.

If you cripple navigation on your site by making visited and
unvisited links look the same, you will frustrate quite a few of
your visitors. Frustrated visitors tend to leave the frustrating
site and try a more user-friendly site. Is that what you want?

--
Stan Brown, Oak Road Systems, Cortland County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2 spec: http://www.w3.org/TR/REC-CSS2/
validator: http://jigsaw.w3.org/css-validator/
Jul 20 '05 #7

P: n/a
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 #8

P: n/a
"Daniel R. Tobias" <da*@tobias.name> writes:
Matt Adams wrote:
As well known I could specify the text color in the body tag like:
<BODY TEXT=WHITE LINK=WHITE VLINK=RED ALINK=WHITE>


Setting links to the same color as regular text is a bad idea.


Though exacerbated in that example by setting both to the default
background colour of most modern graphical browsers, and not setting
something different.

--
Chris
Jul 20 '05 #9

P: n/a
Matt Adams wrote:
As well known I could specify the text color in the body tag like:

<BODY TEXT=WHITE LINK=WHITE VLINK=RED ALINK=WHITE>
This method has been deprecated for 5 years now; you should be using CSS
instead.
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.
This simply can't be done.
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.
This is a feature; this is how it is supposed to work. This is how Web
browsers have handled links for the better part of a decade.
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.


Actually, you need to realize just how badly this will confuse users, if you
find something that "solves" this "problem".

--
Shawn K. Quinn
Jul 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.