Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing a link color back to unvisited

Status
Not open for further replies.

platypus55

Programmer
Aug 15, 1999
32
US
I kind of think you can't do this but thought I'd ask anyway.<br>
Suppose you have a link on a background which matches the linking color. Once you click it, it changes to the vlink color and becomes visible. But on reloading the page, how<br>
can I set it so that it reverts to the unvisited link color.<br>
<br>
Or barring that, is there anyway to change the background color of a table after you have done it. I need this text to alternate between being visible and invisible when you click a button. <br>
<br>
I don't know DHTML yet.
 
couldn't you just skip the link/vlink thing & change the text colors using a CSS style tag & onClick JS events to trigger the color changes? Alternatively; you could name the table (i.e. &lt;table name=tab1 bgcolor=fffff0&gt;) then use a JS onClick like: &lt;a href=# onClick="document.tab1.bgcolor=00000f"&gt;Link Text Here&lt;/a&gt;<br>
<br>
<br>
just a couple of quick suggestions; good luck.<br>
<br>
<br>
-Robherc <br>
robherc@netzero.net
 
Forget about JavaScript for this effect... the easiest way to accomplish this is to use CSS to set the link colors so they never change.<br>
<br>
For example...<br>
Put this in the &lt;HEAD&gt; of your document, all your links, visited or not, will be medium blue, when you mouse over them (IE only), the link will turn light blue, when the link is active it will be Navy blue and the links will not be underlined.<br>
<br>
&lt;STYLE type="text/css"&gt;<br>
a:link {color: MediumBlue; font-family:arial; text-decoration:none; font-size:0.9em;}<br>
a:visited {color: MediumBlue; font-family:arial; text-decoration:none; font-size:0.9em;}<br>
a:active {color: Navy; font-family:arial; text-decoration: none; font-size:0.9em;}<br>
a:hover {color:CornflowerBlue; font-family:arial; text-decoration: none; font-size:0.9em;}<br>
&lt;/STYLE&gt;<br>
<br>
Okay, so that makes for a nice effect, your question was more "how do I change the link color when the user clicks them" but have them reload back in the original color...<br>
<br>
Here's how to do it with JavaScript:<br>
<br>
&lt;script language="JavaScript"&gt;<br>
fnRefreshLinkColor {<br>
}<br>
&lt;/script&gt;<br>
<br>
Put this in your body tag:<br>
&lt;body onload="fnRefreshLinkColor();"&gt;
 
Thanks everybody, I guess I might as well bite the bullet and do it the CSS way. that's the wave of the future and it looks the most elegant. <br>
<br>
It's so great to have these CSS code fragments for just exactly what I want to do. Thanks again!!!
 
Hi, it's me again. I tried changing the background color of a table after the fact, but that didn't work; it basically just didnt do anything. I didn't think you can do that, or maybe it was just a joke. ;) <br>
<br>
I guess I should back off and say what I'm actually trying to accomplish here. I randomly choose a question and it's answer from a database and write them to a web page (done with cgi in case it matters). I want the answer to be invisible. Making the font of it white would do that. I want a button that says "Click here to see the answer" I do control the cgi, so I can make it write whatever I want. <br>
<br>
The answer really isnt a link at all, so forget the link color idea. I would like some CSS code to make the text of the answer change color when the user clicks the button. <br>
<br>
If the user reloads the page, the cgi will choose a different<br>
questin and answer, hopefully with a white-text answer.<br>
<br>
I know Javascript, but I am new to CSS, so please keep this in mind when giving your response. Thank you all very much!!
 
Although it is possible to use a white font color to hide text, it makes more sense to use the CSS properties "visibility" and/or "display" (there's a subtle difference, check it out.)<br>
<br>
The code sample below will demonstrate how to use both the visibility property and the background color & color properties to manipulate the display of a table data cell.<br>
<br>
Note: I whipped this code together in about a minute so forgive the structure. If you use it or something like it, consider encapsulating the display toggling into a single function and test for visibility. Additionally, this code is IE only. You can achieve the same effect with Netscrap but the Object Model is a little different (and much poorer) so have fun.<br>
<br>
--------------------------<br>
<br>
&lt;html&gt;<br>
&lt;head&gt;<br>
&lt;title&gt;&lt;/title&gt;<br>
<br>
&lt;script language="JavaScript"&gt;<br>
<br>
function fnShowAnswers () {<br>
document.all.tdAnswer.style.visibility = "visible";<br>
document.all.tdAnswer.style.backgroundColor = "black";<br>
document.all.tdAnswer.style.color = "white";<br>
document.all.tdQuestion.style.backgroundColor = "white";<br>
document.all.tdQuestion.style.color = "black";<br>
}<br>
function fnHideAnswers () {<br>
document.all.tdAnswer.style.visibility = "hidden";<br>
document.all.tdAnswer.style.backgroundColor = "white";<br>
document.all.tdAnswer.style.color = "black";<br>
document.all.tdQuestion.style.backgroundColor = "black";<br>
document.all.tdQuestion.style.color = "white";<br>
}<br>
&lt;/script&gt;<br>
<br>
&lt;style type="text/css"&gt;<br>
#tdQuestion {<br>
background-color:black;<br>
color:white;<br>
}<br>
#tdAnswer {<br>
visibility: hidden;<br>
}<br>
&lt;/style&gt;<br>
<br>
&lt;/head&gt;<br>
&lt;body&gt;<br>
<br>
<br>
&lt;table width="50%" cellpadding="3" cellspacing="0" border="1"&gt;<br>
&lt;tr&gt;<br>
&lt;td id="tdQuestion" width="60%"&gt;Which is more fun, CGI or ASP?&lt;/td&gt;<br>
&lt;td id="tdAnswer" width="*"&gt;ASP of course!&lt;/td&gt;<br>
&lt;/tr&gt;<br>
&lt;/table&gt;<br>
<br>
&lt;form&gt;<br>
&lt;input type="button" value="Show Answer" onclick="fnShowAnswers();"&gt;<br>
&nbsp;&nbsp;&nbsp;<br>
&lt;input type="button" value="Hide Answer" onclick="fnHideAnswers();"&gt;<br>
&lt;/form&gt;<br>
<br>
&lt;/body&gt;&lt;/html&gt;
 
Thanks!! I think I can have some fun with that. A lot of people still use Netscape, I wish those two browsers would get it together.
 
I tried the code above in Vn 4.5 of MSIE for Macintosh (which is what I have.) The answer is invisible, and it is in the page source, but clicking the show button does not make it visible for me even though the logic appears to be flawless. Is it because it's Macintosh? <br>
<br>
This code is at <br>
A. How can I make this thing work?<br>
B. How can I refine it to make it xplatform, I really do try to make my site accessible for everybody.
 
I just tried it on MSIE 5 on Windows and it doesn't work there either.
 
OK....here's a simple JavaScriptlet that'll write the answer on-screen after the button has been pressed....inster the following into your document IN PLACE OF the normal <i>&lt;a href=whatever.foo&gt;&lt;/a&gt;</i> that surrounds the button.<br>
<br>
<i>&lt;a href=# onMouseClick=&quot;document.writeln('&lt;font color=000000 size=4&gt;&lt;br&gt;&lt;br&gt;Your Answer Here')&quot;&gt;&lt;/a&gt;</i><br>
<br>
This <i>should</i> work on MSIE & Netscape versions 4+ on any platform (but watch Netscape v4.0 & I.E. 3.0-4.0....sometimes buggy) <p>-Robherc<br><a href=mailto:robherc@netzero.net>robherc@netzero.net</a><br><a href= > </a><br>*nix installation & program collector/reseller. Contact me if you think you've got one that I don't :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top