By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,089 Members | 2,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,089 IT Pros & Developers. It's quick & easy.

how to set link's "visited" property/pseudo-class without clicking on the link

P: n/a
Hi,

I would like to set the link's "visited" pseudo-class with javascript
without clicking on the link. My goal is to update the link's color
(previously set in the CSS file) to be "visited" without actually
clicking on the link and then clicking "back" in the browser.

Does anyone know how? Here are the following things I've already
tried to no avail:
var obj = document.getElementById("idOfMyLink");

//obj.visited=true; // NO
//obj.style.visited=true; // NO
//obj.click(); // NO, performs a click and takes me away from
current page

/*
// Setting the src of an iframe on the same page, trying to
"stuff" this URL into browser's "History"

var theFrame = document.getElementById("myiframe");
theFrame.src = obj.href;

// NO. The iframe does go to correct URL, but the link's color
doesn't update.
*/

Any ideas?

Thanks for your help!

Apr 27 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Apr 27, 3:23 pm, friday13 <vbo...@gmail.comwrote:
Hi,

I would like to set the link's "visited" pseudo-class with javascript
without clicking on the link. My goal is to update the link's color
(previously set in the CSS file) to be "visited" without actually
clicking on the link and then clicking "back" in the browser.

Does anyone know how? Here are the following things I've already
tried to no avail:

var obj = document.getElementById("idOfMyLink");

//obj.visited=true; // NO
//obj.style.visited=true; // NO
//obj.click(); // NO, performs a click and takes me away from
current page

/*
// Setting the src of an iframe on the same page, trying to
"stuff" this URL into browser's "History"

var theFrame = document.getElementById("myiframe");
theFrame.src = obj.href;

// NO. The iframe does go to correct URL, but the link's color
doesn't update.
*/

Any ideas?

Thanks for your help!
This is not a self-"bump"... just a follow-on question with a
possible work-around.
So this is a hack, but a way to SORT OF get the link "visited" is is
to open a new window with that URL:

var win = window.open( url,'mywindow','width=100,height=200');

And then close it right away.

win.close();

But the link-color is NOT updated until I refresh the page.

So this generates a 2nd question:

Is there any way to FORCE the link to update its color??

Thanks.

Apr 28 '07 #2

P: n/a
On Apr 28, 12:23 am, friday13 <vbo...@gmail.comwrote:
Hi,

I would like to set the link's "visited" pseudo-class with javascript
without clicking on the link. My goal is to update the link's color
(previously set in the CSS file) to be "visited" without actually
clicking on the link and then clicking "back" in the browser.

Does anyone know how? Here are the following things I've already
tried to no avail:

var obj = document.getElementById("idOfMyLink");

//obj.visited=true; // NO
//obj.style.visited=true; // NO
//obj.click(); // NO, performs a click and takes me away from
current page

/*
// Setting the src of an iframe on the same page, trying to
"stuff" this URL into browser's "History"

var theFrame = document.getElementById("myiframe");
theFrame.src = obj.href;

// NO. The iframe does go to correct URL, but the link's color
doesn't update.
*/

Any ideas?

Thanks for your help!
You could define a class in the CSS then just change the class of the
link ;p

Apr 28 '07 #3

P: n/a
On Apr 27, 5:00 pm, tsukasa...@gmail.com wrote:
On Apr 28, 12:23 am, friday13 <vbo...@gmail.comwrote:


Hi,
I would like to set the link's "visited" pseudo-class with javascript
without clicking on the link. My goal is to update the link's color
(previously set in the CSS file) to be "visited" without actually
clicking on the link and then clicking "back" in the browser.
Does anyone know how? Here are the following things I've already
tried to no avail:
var obj = document.getElementById("idOfMyLink");
//obj.visited=true; // NO
//obj.style.visited=true; // NO
//obj.click(); // NO, performs a click and takes me away from
current page
/*
// Setting the src of an iframe on the same page, trying to
"stuff" this URL into browser's "History"
var theFrame = document.getElementById("myiframe");
theFrame.src = obj.href;
// NO. The iframe does go to correct URL, but the link's color
doesn't update.
*/
Any ideas?
Thanks for your help!

You could define a class in the CSS then just change the class of the
link ;p- Hide quoted text -

- Show quoted text -
@tsukasa

Ok, so how do I know the "color" value of visited links for that page?

I'm trying to write a greasemonkey script that could apply to pages
that I don't own/create.

Question 3:

How do I get the value of "a:visited" that is defined in a CSS file?
Or what if it's not [user is using the regular blue/purple combination
from browser?

Thanks.

Apr 28 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.