Detect Visited Link In Chrome

前端 未结 1 826
无人共我
无人共我 2021-01-05 16:34

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{
   co         


        
相关标签:
1条回答
  • 2021-01-05 17:29

    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.

    0 讨论(0)
提交回复
热议问题