Changing href with jQuery no longer triggers: visit style

My SharePoint site should retain the a: visited style defined in CSS for links. I added the following code that adds "& Source = /" to each href. It seems that by changing href via jQuery, the browser only “sees” the original href and therefore never launches the a: visited style, since there is no match ...

$("table[class='ms-listviewtable'] td[class='ms-vb2'] a") .removeAttr("onclick") .attr('href', function(){ return $(this).attr('href') + '&Source=/'; }); 
+4
source share
3 answers

IE doesn't seem to support :visited styles for dynamically updated links. I tested only IE8, but if it does not work in the latest version, I do not expect it to work in IE 6/7

IE only supports the most basic scenario, when a visitor clicks on a link that goes to another page, and then clicks the "Back" button to return to the previous page. Only after that the link displays the style :visited .

It works fine in Firefox 3; links are formatted correctly even when their href attributes are updated via javascript.

I created a test page that allows you to try various links and methods: http://jsbin.com/odoqo (edited via http://jsbin.com/odoqo/edit )

Note. I used the test page only in Firefox 3 and IE 8, it will probably break in IE 6/7

+3
source

Adding a query string parameter makes the browser see it as a completely different URL that has not been visited. The browser does not know that the Source parameter does not change the destination of the link.

Another thing you need to pay attention to is how specific your styles are - sometimes the “table” cancels “: visited”, so you also need the “table a: visited”.

+1
source

All Articles