在Chrome中检测访问的链接 [英] Detect Visited Link In Chrome

查看:244
本文介绍了在Chrome中检测访问的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Chrome和Firefox的userscript,并且正在检查用户访问的链接。我有

  a {
颜色:蓝色;
}

a:visited {
color:red!important;
}

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

$ $ p $ code alert(window.getComputedStyle(document.getElementById(myLink),null).getPropertyValue(color ))

每个链接都会返回红色,全部返回蓝色。

我想知道如何使用Chrome浏览器实现查找访问过的链接。 JQuery的代码或正常的JavaScript代码是好的。提前致谢。

解决方案

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

  //测试我在JS控制台中使用。 
//:visited被getComputedStyle检测不到。
函数getLinkColor(url){
var a = document.createElement('a');
a.href = a.textContent = url;
document.body.appendChild(a);
返回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


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.

解决方案

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.

这篇关于在Chrome中检测访问的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆