Solved

Anchor Links Visited State

Posted on 2004-10-20
12
1,440 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +3
12 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 12364617
We need to see the code.

Cd&
0
 

Author Comment

by:Joana
ID: 12364765
<!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
ID: 12366992
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:Daedalus05
ID: 12367007
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
ID: 12367148
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
 
LVL 49

Expert Comment

by:Roonaan
ID: 12367359
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
ID: 12368029
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
ID: 12368109
@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
ID: 12368140
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
ID: 12629904
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Button on Table, name table1 not working 4 34
..ignore the Question 1 21
Html date format 9 20
output in HTML format powershell 6 21
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

733 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