I am using a userscript for Chrome and Firefox and I am checking for links that have been visited by the user. I have
a{
color: blue;
}
a:visited{
color: red !important;
}
in my css imported as soon as the page loads. The a-links on the page that I have visited are colored red instead of default of blue. I then use:
alert(window.getComputedStyle(document.getElementById("myLink"), null).getPropertyValue("color"))
on each link and they all return red for the visited links in Firefox but in Chrome they all return blue.
I was wondering how to implement finding visited links using javascript with Chrome. Jquery code or normal javascript code is fine. Thanks in advance.
You can parse all links on the page and and get their CSS color property. If a color of the link is a match to the color of unvisited link you defined in CSS the this link is unvisited. This kind of technique usually used to determine all visited links.
If you cannot open your VISITED LINKS file correctly, try to right-click or long-press the file. Then click "Open with" and choose an application. You can also display a VISITED LINKS file directly in the browser: Just drag the file onto this browser window and drop it.
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.
A_horse_with_no_name is right. The :visited
security issue was fixed in 2010 by the browser vendors, after a nifty demo (Spyjax; no longer up) demonstrated that any webpage could discover whether you've visited any given URL. You can verify that getComputedStyle
on a link no longer returns the :visited
color--even within the same domain:
// Test I used within the JS console.
// :visited is no longer detectable by getComputedStyle.
function getLinkColor(url) {
var a = document.createElement('a');
a.href = a.textContent = url;
document.body.appendChild(a);
return document.defaultView.getComputedStyle(a, null).color;
}
getLinkColor('http://stackoverflow.com/questions/5394099/detect-visited-link-in-chrome');
getLinkColor('http://stackoverflow.com/some-fake-path');
For Chrome extensions, if you want to detect whether a user has visited a URL, I think you'll have to request the "history"
permission and call chrome.history.getVisits
.
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