Solved

Anchor Links Visited State

Posted on 2004-10-20
12
1,424 Views
Last Modified: 2012-06-21
Hello
I have a page with anchor links
Whenever i go into the page the links are set to the visited state - even if tehy have never been clicked on.

How do i stop this from happening?

Thanks Heaps

JO
0
Comment
Question by:Joana
  • 3
  • 2
  • 2
  • +3
12 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
We need to see the code.

Cd&
0
 

Author Comment

by:Joana
Comment Utility
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
      <title>test</title>
      <style type="text/css">
      a, a:link {
            color: lime;
        }
        
       a:visited {
            color: green;
        }
        
       a:hover {
            color: pink;
        }

       a:active {
            color: red;
        }       
      
      </style>
</head>
<body>

<p>
<a href="#C4">
See also Chapter 4.
</a>
</p>

<p>
<h2>Chapter 1</h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 2</h2>
<p>This chapter explains ba bla bla</p>

<h2>Chapter 3</h2>
<p>This chapter explains ba bla bla</p>

<a id="C4"><h2>Chapter 4</h2></a>
<p>This chapter explains ba bla bla</p>


</body>
</html>
0
 
LVL 3

Expert Comment

by:Daedalus05
Comment Utility
You can use a javascript to overcome this, to some extent, with a mod of your CSS. Something like this:

CSS MOD: Replace A:VISITED with the following
A .visit { color: green }

JavaScript: Using a cookie object set to expire in one month, and onClick dynamic changes, we provide a new visited link setup:
<script type="text/javascript">
 if(document.cookie == "") {
  var dt = new Date();
  var yr = dt.getYear();
  if(yr < 1900) yr += 1901; else yr += 1;
  document.cookie = "expires: "+new Date(yr, dt.getMonth(), dt.getDate()).toGMTString();
 }

 if(document.location.toString().indexOf("#") > 0) {
  var id = document.location.toString().substring(document.location.toString().indexOf("#") + 1);
  visitLink(id);
 }

 function visitLink(id) {
  document.cookie = id + "=V";
  document.getElementById(id).className = "visit";
 }
</script>

This should assure that outside links to this page content at one of the #id positions will be covered as well as same-page links.
0
 
LVL 3

Expert Comment

by:Daedalus05
Comment Utility
Oops... Cookie expires in one year. To make the expire in one month, change the if(document.cookie == "") { } part to this:
if(document.cookie == "") {
 var dt = new Date();
 var yr = dt.getYear();
 if(yr < 1900) yr += 1900;
 var mo = dt.getMonth() + 1;
 if(mo > 11) mo -= 11;
 document.cookie = "expires: "+new Date(yr, mo, dt.getDate()).toGMTString();
}
0
 
LVL 3

Expert Comment

by:Daedalus05
Comment Utility
Sorry... my code doesn't seem to work as I expected now that I've tested it, although I presume something very similar could do the trick. Perhaps it will give you, or another EE Expert, the inspiration you need to find the answer. In the meantime... I'm going to bed! :-P
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 49

Expert Comment

by:Roonaan
Comment Utility
Use an extra css class:

<a class="anchorlink" href="#C4">See also chapter 4</a>

<style type="text/css">
a.anchorlink:visited {color:lime;}
</style>

Regards

-r-
0
 
LVL 31

Expert Comment

by:seanpowell
Comment Utility
Not sure why you would need any extra CSS.

You just need to code the anchor like this:
<h2><a name="C4" id="C4">Chapter 4</a></h2>

Anchor tags are not supposed to be styled like a link (since they aren't links...)
Because you left out the name attribute, the browser assumed it was a link.

Sean
0
 
LVL 49

Expert Comment

by:Roonaan
Comment Utility
@Sean: That would be correct if Joana had used the word anchor like you expected her to.

In her example she refers to an anchor link as a hyperlink linking to an anchor on the same page:
<a href="#C4">See chapter 4</a>

Obviously these links are always in visited state, because they always link to the page the visiter is currently on. Therefor the page will be visited.

To counteract this effect she could add a class="anchorlink" which colors this type of links as if they are always unvisited.

Regards

-r-
0
 
LVL 31

Expert Comment

by:seanpowell
Comment Utility
Thanks Roonon - perhaps I misunderstood the question.

Wouldn't be the first time :-)

Sean
0
 
LVL 5

Accepted Solution

by:
Alex Ene earned 125 total points
Comment Utility
The current CSS specs do not allow you to do that inside a single document.
You will have to use either some js or frames.
tried with frames and it works.
there is another similar question that gives you the answer: its not possible inside same document.
http://www.experts-exchange.com/Web/Web_Languages/CSS/Q_20257755.html


Sorry it cant be done the way you described it :(

Hope you can do some workaround.

Regards,

Alex
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now