Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CSS visited property for href to a file

Tags:

html

css

I have this HTML of 2 anchor tags, one to a file and one to google

<a href="http://example.com/files/foobar.csv">
    http://example.com/files/foobar.csv
</a>
<a href="http://google.com">
    Google
</a>

I also have this CSS to make visited anchor tags red.

a:visited {
    color: #ff0000;
}

When I click on the google link, the link turns red as expected because I have visited it.

When I click on the file however, the link does not turn red.

So it seems file paths work differently than url paths.

How can I get the visited property working on anchor tags with href to a file

like image 443
Goose Avatar asked Mar 07 '17 19:03

Goose


People also ask

What does the CSS visited keyword do?

The :visited CSS pseudo-class represents links that the user has already visited. For privacy reasons, the styles that can be modified using this selector are very limited.

Which CSS property is used to change the style of visited links?

The :visited selector is used to select visited links. Tip: Use the :link selector to style links to unvisited pages, the :hover selector to style links when you mouse over them, and the :active selector to style links when you click on them.

Which link shows visited link?

By default, a link will appear like this (in all browsers): An unvisited link is underlined and blue. A visited link is underlined and purple.


2 Answers

Could you try to insert the URL directly in Browser History.

You can do something like:

HTML:

$(".file-link").click( function () {
  $(this).attr("href");
  var stateObj = { foo: "bar" };
  window.history.pushState({ title: "Services" }, "foobar.csv", $(this).attr("href"));
}); 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#/files/foobar.csv" class="file-link">
    http://example.com/files/foobar.csv
</a>
<a href="http://google.com">
    Google
</a>
like image 191
Alexandre Martins Klostermann Avatar answered Oct 22 '22 11:10

Alexandre Martins Klostermann


Nice answer is also listed here: text-decoration not working for visited state link

You can done with this jquery addClass.

Demo code

$('a').click(function(){
    $(this).addClass('visited');
});

CSS

.visited {
  color: green;
  text-decoration: line-through;
}

fiddle demo: https://jsfiddle.net/nikhilvkd/7y2fyytw/

like image 1
Anton Shchastnyi Avatar answered Oct 22 '22 09:10

Anton Shchastnyi