最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - is it possible to get anchor visited state from javascript? - Stack Overflow

programmeradmin3浏览0评论
  1. i'm using jquery. i have a anchor list. i'm enumerate anchors, if it visited, set display:none;
  2. i need when click on the anchor, anchor will changed to visited state from javascript?

How can i do?

  1. i'm using jquery. i have a anchor list. i'm enumerate anchors, if it visited, set display:none;
  2. i need when click on the anchor, anchor will changed to visited state from javascript?

How can i do?

Share Improve this question edited Oct 18, 2009 at 13:14 ebattulga asked Oct 18, 2009 at 13:07 ebattulgaebattulga 11k20 gold badges81 silver badges119 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 5

Yeah, see here for an example. It uses getComputedStyle to find out if a link has been visited. There's also a variant of this hack that doesn't require scripting.

The relevant part of the example is this (modified for clarity):

a:visited {
    color: #00f;
}

var link = document.createElement('a');
link.href = 'http://example./';
document.body.appendChild(link);
var color = document.defaultView.getComputedStyle(link, null).getPropertyValue('color');       
// check for visited
if (color == "rgb(0, 0, 255)") {           
    alert(link.href + ' has been visited');
}

May I ask what do you need it for?

Edit: WRT #2, you could open the link in an iframe. That would mark it as visited in the browser history. Like so:

var iframe = document.createElement('iframe');
iframe.src = 'http://example./';
document.body.appendChild(iframe);

Edit: You can create new CSS rules with JS. There's a jQuery plugin to make it more simple. Basically, you would do it like this:

$.rule('a:visited { color: #f06 !important }').appendTo('style');

How about doing it through CSS?

a:visited {display:none;}
发布评论

评论列表(0)

  1. 暂无评论