Browser Fails to Recognize AJAX Links as Visited

It appears that the styles for a:visited do not apply to links that are loaded via JavaScript. When a user clicks on a standard link, it shows as visited right away and even after refreshing the page. I'm uncertain if this issue is specific to jQuery Mobile (where I initially noticed it) or if it's a limitation in browsers that I wasn't aware of?

Answer №1

If you want your code to work with history and visited links styling, consider changing the location.hash.

It is important to note that the styling of visited links may vary across different browsers due to the privacy vulnerability in browsing history popularized by the Did You Watch Porn website.

Answer №2

a:visited applies to links that have been clicked and are in the browser's history.

If you utilize AJAX to prevent navigation to a specific URL, that URL will not be added to the browsing history.

To address this issue, opt for using # links instead.

Answer №3

a:visited is only activated when a link is clicked.

In the case of an AJAX call, clicking the link generally results in a return value of 'false' (Even using a hash solution like <a href="#">link</a> still returns false to prevent jumping to the top of the page).

As a result, the link is never executed and therefore remains unmarked as visited.

Answer №4

Let's not change the a element's href to a hashed url as suggested by others, as it could disrupt the user experience. This would result in double loading for those wanting to open in new window, and cause issues for search engines and users with Javascript disabled.

The problem arises when using hashes to transition your website into a RIA (rich internet application), where links point to mysite.com/page but actually access mysite.com/#/page, leading to inconsistencies in visiting the original page.

A better solution is to utilize the HTML5 History API, allowing direct URL changes and enabling tracking of URL changes without the use of hashes. For more information on the comparison between hashes, hashbangs, and HTML5 History API, check out this link: https://github.com/browserstate/history.js/wiki/Intelligent-State-Handling, which also provides sample code for upgrading your website with the HTML5 History API.

jQuery Mobile is set to adopt the HTML5 History API in the future (currently in progress), so it may be worth waiting until this implementation is complete.

Answer №5

One way to apply the same style to a link as you would for a:visited is by setting a class in the ajax callback.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to retrieve file using ajax (Error 500)

When trying to access a file via Ajax, I keep encountering an error 500. The file I need access to is located here: /templates/***/sections/popular.php While it functions correctly on localhost (MAMP), uploading my site to the server has caused issues w ...

Conceal a column within a table by double-clicking

I'm working on a project with a table, and I'd like to implement a feature where a column hides when double-clicked. I've seen various solutions for hiding columns on Stack Overflow, but I could use some guidance on where to add the ondblcli ...

Step-by-step guide for making a CSS triangle design that is compatible across different browsers

Here's a common CSS code for creating a CSS triangle: display: inline-block; vertical-align: middle; content: " "; border-right: 4px solid transparent; border-left: 4px solid transparent; border-top: 6px solid black; width: 0; height: 0; Click here ...

Guide to retrieving data from a URL and storing it in a string variable with JavaScript

Attempting to retrieve the JSON data from a specific URL and store it in a variable. The code snippet below successfully loads the JSON into a div element: $("#siteloader").html('<object data="MYURL">'); However, the goal is to extract t ...

How can the parent div's height be determined by the child div when using position: absolute?

I am struggling with setting the height of a parent div that contains a nested child div with absolute positioning. The child div has a fixed height of 652px, but I cannot seem to get the parent div to match this height. I have tried adjusting the clear an ...

What causes the HTML element's X position value to double when its X position is updated after the drag release event in Angular's CDK drag-drop feature?

I am facing a challenge with an HTML element that has dual roles: Automatically moving to the positive x-level whenever an Obsarbalve emits a new value. Moving manually to both positive and negative x-levels by dragging and dropping it. The manual drag a ...

Exploring ways to incorporate various classes into my validate() elements using jQuery

I'm currently using the jQuery method validate to verify this particular form: <form id="emailRecover"> <div class="row light-field-container error-container"> <input type="text" id="dniPassword" name="dniPassword" requ ...

Leveraging Ajax in WordPress for email delivery

I'm feeling a bit lost trying to implement Ajax for sending emails via a web form I built. I'm unsure how to make Ajax work within Wordpress. Firstly, I created an action: add_action( 'wp_ajax_siteWideMessage', 'wpse_sendmail&apo ...

Activate the overflow feature within native-base cards

I have a unique design element on a website that showcases an image overflowing off a card. The image has a negative margin-top of -50, creating this effect. Now I'm trying to replicate this design in react-native using native-base components. Here i ...

Display a pdf stream within a fresh window

I have a PDF document generated on the server that I need to display on the client side. The code on the server looks like this: ByteArrayOutputStream baos = generatePDF(); response.setContentType("application/pdf"); response.setHeader("Content-Dispositio ...

What is the best way to store a range object obtained from getSelection in order to recreate it on a separate page load?

My goal is to develop a web application that enables users to highlight selected text on a webpage with the click of a button. I want these highlights to persist even when the user returns to the page. So far, I have achieved: var selectedRange = documen ...

Having trouble running the script, chrome error with message passing?

I've hit a roadblock while working on my Chrome extension and could use some assistance. The main issue I'm facing is getting the script to run when activated by the user through an on/off switch in the popup window. It seems like there might be ...

A quick guide on automatically populating text boxes with characteristics of the item chosen from a drop-down menu

On my webpage, I am looking to automatically populate textboxes with information (such as common name, location, etc.) of the selected shop from a dropdown list without having to refresh the page. Here is the dropdown list: <select id="shops" class="f ...

Create and adapt dynamic tiles to fit within the available width

I am looking to create a dynamic tile (div) that adjusts based on the number of users available, similar to how it works in Microsoft Teams meetings. For example, if there is only one user, the div should occupy the full screen. When there are two users ...

Ways to conceal rows within an implicit grid

In the code snippet below, CSS Grid is used to adjust the number of columns for wider containers. When dealing with narrower containers (such as uncommenting width: 80vw or resizing the example), implicit rows are added (with only two being specified in th ...

Google Maps API - Custom Label for Map Markers

I am trying to implement a custom map on my website, and everything seems to be working fine except for one issue. The red marker on the map needs to have a label, but I don't want to use an additional image as an icon. Is there a way to add a label ...

jQuery page hanging during DOM update with large data set

I am currently using a jQuery post method with the following structure: $.post("/SearchCompetitor/Index", { username: _username }, StartLoading()) .done(function (data) { if (data !== "UsernameErro ...

Obtaining a background image within a keyframe

I have been experimenting with keyframe animations and am looking to incorporate multiple images into the animation. Specifically, I want to switch out the image every 10% increment to depict someone running. Despite my efforts to use a background-img in ...

Fixing the reinitialization of a data table

I've been grappling with this issue for quite some time now (exactly 5 days) and I keep encountering the following error. DataTables is throwing a warning: table id=activities-table - Cannot reinitialize DataTable. For more details regarding this ...

Retrieve the parent id using jQuery, not the children elements

Looking for a way to add a jQuery click event to the parent element with class .menu-option and retrieve its id, "#main-link-1", without changing the HTML structure: <div id="main-link-1" class="menu-option"> <div id="icon" class="menu-icon"> ...