agarwal
agarwal

Reputation: 46

to show visited color on javascript link

I have a hyperlink which is calling the JavaScript function. My link renders as follows

<a class="popup" onclick="return launchModalNews('http://google.com',this)" href="http://google.com/">google</a>

In my JavaScript I am opening this link as popup and I return false so that I don't navigate away from page.

Due to this my link doesn't show as visited.

To show as visited I have create a hidden iframe and I am setting the src on the link click so that IE maintains the history.

This works fine and IE is able to show the link as visited but the issue is that now when I try to check whether the link is visited or not I am not getting proper color.

I have used following ways:

document.defaultView.getComputedStyle(element, null).color 
jQuery(element).css('color');

this all give the normal link color not the visited one while In page I can see that it has applied the visited link color how can I get the real color i.e. visited color using jquery/javascript?

Secondly this method for showing visited link works in IE but not in chrome.Is there any idea how to achieve this on chrome?

[Update to the replies] First of all this is not google.com this is another link.i just gave an example secondly If I add class at runtime then it works fine for that scenario but once the page refreshes then I don't get the visited links and I will not able to add the custom class. I have tried "a:visted" in jquery but it returns 0 items.I want to check the color so that I can optimise it. If I get the color as visited then I will not set the src for iframe because that link is already in browser history and the browser take care of the visited link

Upvotes: 1

Views: 2064

Answers (1)

Pete
Pete

Reputation: 58462

You could add a class (which is styled in the same way as actual visited links) when you click your link:

$('.popup').click(function(e) {
    e.preventDefault();
    launchModalNews('http://google.com',this);
    $(this).addClass('visited');
});

Upvotes: 1

Related Questions