繁体   English   中英

检测Chrome中的访问链接

[英]Detect Visited Link In Chrome

我正在使用Chrome和Firefox的用户脚本,我正在检查用户访问过的链接。 我有

a{
   color: blue;
}

a:visited{
   color: red !important;
}

在页面加载后立即导入我的CSS。 我访问过的页面上的a-links为红色,而不是默认的蓝色。 然后我用:

alert(window.getComputedStyle(document.getElementById("myLink"), null).getPropertyValue("color"))

在每个链接上,它们都为Firefox中的访问链接返回红色,但在Chrome中它们都返回蓝色。

我想知道如何使用javascript与Chrome实现查找访问过的链接。 Jquery代码或普通的javascript代码很好。 提前致谢。

A_horse_with_no_name是对的。 :visited浏览器供应商在2010年修复:visited安全问题,经过一个漂亮的演示( Spyjax ;不再向上)证明任何网页都可以发现您是否访问过任何给定的URL。 您可以验证链接上的getComputedStyle不再返回:visited color - 即使在同一个域中:

// 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');

对于Chrome扩展程序,如果您想检测用户是否访问过网址,我认为您必须请求"history"权限并调用chrome.history.getVisits

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM