Ajax and link how to make a:visited work when using ajax

Asked

Viewed 201 times

2

I did a site recently this week, vhtvshows.com.br. When you click on a series to watch and choose the episode ajax takes the link and puts it in my div, but when I go back the link is not in the color I put in CSS:

#exemplo a:visited{
color:#0099ff;
}

Already when I open the link in new tab where the ajax will not work perfectly a:visited.

Does anyone know what I can do to make it worth a:visited even using ajax ? don’t want to have to use " iframe".

  • You need to load ajax based on the url, using a hash like on that website. Note that when switching pages is loaded with ajax, however the url tbm exchange, and when you enter a different url directly the correct content is already loaded... making the site that way you can use a:visited

  • The guy blz think using the $_GET will get the expected result as it will be loaded into the computer’s history thus making the a:visited work. Obliged.

1 answer

1

Unfortunately I don’t think it is possible, as :visited will only work for the sites that are present in the browser history.

But you can still add a class to the visited links.

If your browser supports Html5, you can use history object to force the AJAX link to enter the history:

var linkOpen = document.getElementById("<ID do seu Link>");
var hrefAtual = window.location.href;
history.pushState(null, null, linkOpen.href);
history.pushState(null, null, hrefAtual);

JSFIDDLE

  • can you give me an example of what to do in this case without using visited ? obbrigado

  • 1

    Could provide the source of information talking about :visited depreciation?

  • @Guilhermenascimemto, I looked here, but I did not find, what I found was that some elements of HTML4 were depreciated in favor of those of CSS, possibly I assimilated this information in the wrong way.

  • @Gabriel, are you on the same domain? It might be an HTML5-based solution?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.