AJAX links not found A: Visited

I notice that a:visited styles do not work with links that are requested via JavaScript. At the standard click of the user, though, exactly the same links are registered as visited, both immediately and after subsequent updates. I'm not sure if this is unique to jQuery Mobile (where I first came across this) or is it a browser limitation that I did not know about?

+4
source share
5 answers

You will probably need to change location.hash if you want it to work with history and visiting links.

Keep in mind that the visited links style works somewhat inconsistent between the browser after the visited links based on the vulnerability of the privacy viewing history was made popular. You watched porn .

+2
source

a:visited matches any link pointing to a URL that is in your browser history.

If you use AJAX to cancel URL navigation, the URL will never appear in your browser history.

You can fix this using the # links.

+2
source

a:visited launched only if the link is "completed".

The AJAX call link usually returns false (the hash solution ( <a href="#">link</a> ) still returns false, otherwise the user will go to the top of the page).

Thus, the link is never "executed", therefore it is not marked as visited.

+1
source

Well, please do not change a element href to point to a hashed URL, as other responders say - this will disrupt the user. If they want to open in a new window, then you will need to double the load, if you make a change on the server side, this will break the search engines and js-disabled users.

The problem is that if you use hashes to update your website in the RIA (rich internet application), the links will point to mysite.com/page , but you really get access to mysite.com/#/page so that you did not actually attend the original.

The right solution here is to use the HTML5 History API, which allows you to directly change the URL and connect to URL changes (therefore, hashes are no longer necessary). You can learn more about the pros and cons of hashes against hash bands and the HTML5 history API here: https://github.com/browserstate/history.js/wiki/Intelligent-State-Handling - it also contains sample code for updating your site using the HTML5 history API.

jQuery Mobile is planned to be used in the HTML5 history API in the future (it currently works), but at the moment I suggest that this be realized.

+1
source

You can always set the class by reference via the ajax callback, which shares the style with: visited.

0
source

Source: https://habr.com/ru/post/1343376/


All Articles