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
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.
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.
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.
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>
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With