When the focus() method is used to programmatically set the cursor in a JQuery input element, the blinking cursor does

I have a situation where I have two sibling divs. On the left side, I am loading a PDF document, while on the right side, I have input fields controlled by jQuery.

My challenge arises when I try to select and delete the value from the input using the mouse and backspace key. When I select the value from the input field, the mouse hovers over the PDF document. Subsequently, when I press the backspace key to delete the selected value, although the value is deleted and the document.activeElement shows the input field, there is no visible cursor blinking. As a result, if I start typing again, the text displays in reverse order.

It seems to be a limitation with the browser, but I am wondering if there is a workaround for this issue.

I have attempted several options listed below, but none have been successful:

  1. Getting the input element and using inputele.focus() and .select() when the backspace is clicked.
  2. Wrapping inputele.focus() in a setTimeout function.
  3. Using setSelectionRange.
  4. Implementing event bubbling and capturing when the mouse enters the PDF and when the backspace key is pressed (e.stopPropagation, e.preventDefault, etc).

I have spent a significant amount of time searching for a workaround online but without success. If anyone has a solution, please do share as it would be greatly appreciated.

Below is an example code snippet:

<div class="container" style="
    display: flex;
    align-items: center;
">
  <div>
  <iframe src="https://www.ifpi.org/content/library/DMR2010.pdf">
  
  </iframe>
</div>
<div>
   <input id="inputId" type="text">
</div>
  
</div>

https://i.sstatic.net/RhOl5.gif

Answer №1

This particular issue was outlined in a response to a Chromium Bug report, which can be found at https://bugs.chromium.org/p/chromium/issues/detail?id=1402816

"A MouseDown on a main frame does not trigger capture, so if you move the mouse to a cross-origin iframe and release the button, the main frame does not receive the MouseUp (it was sent to the iframe's renderer process only). The main frame behaves as if there is still a drag in progress, resulting in some strange things like typing into an input element having the text come out backward."

It appears that this issue was reportedly resolved towards the end of the year 2023, following multiple bug reports dating back to April 2019. More information can be found at . However, it's advised to remain cautious as similar manifestations could occur through other avenues.

The recommended course of action is to check if updating your browser resolves this specific bug and any related causes.

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

Troubleshooting a JavaScript project involving arrays: Let it pour!

I'm a beginner here and currently enrolled in the Khan Academy programming course, focusing on Javascript. I've hit a roadblock with a project called "Make it rain," where the task is to create raindrops falling on a canvas and resetting back at ...

Ways to organize two columns of flexible items on a responsive display

Can someone assist me with CSS flexbox for responsive screens? Below is the layout of the flex container and items on a desktop screen: https://i.sstatic.net/AXBHw.png The container has flex and flex-wrap properties applied, with each column having flex: ...

How to solve issues with jQuery functionality in an ASP.NET MVC3 view?

I'm encountering an issue with my ASP.NET MVC3 page. I have a view that contains a form to create an item for a specific model. Here is the code snippet: @model testPro.Models.AddItemModel @{ ViewBag.Title = "New"; } <script src="@Url.Con ...

Animate the downward movement of the parent of a specific element, while simultaneously animating the upward motion of all others that are

When clicking a button, I am trying to slide down only the ul elements that are parents of the li.newlist element, while sliding up all the others. Although I have successfully managed to slide down the desired elements, I am unsure how to define the secon ...

JSON Serialization of numeric data types

It came to my attention that the website generates the same Base64 string for payloads containing numerical values written in different notations. An interesting example is the output for these two payloads: { "value": 0.000001 } { "val ...

Is there a way to display icons alongside each option in the dropdown menu?

I have a dropdown icon (pumpkin 1) div that is causing spacing issues with the other icons on the page. The problem is that it has a dropdown functionality which needs to overlay the text at the bottom. I want to display all icons next to each other (1,2, ...

"Upon calling an asynchronous method within another method, it appears that no progress is being displayed

I've created a `node-js` `db.js` class that retrieves an array of data for me. //db.js const mysql = require('mysql'); var subscribed = []; const connection = mysql.createConnection({ host: 'localhost', user: 'root' ...

Utilizing jQuery show() and hide() methods for form validation

I created a form to collect user details and attempted to validate it using the jQuery hide and show method. However, I seem to be making a mistake as the required functionality is not working correctly. What am I missing? I have searched for solutions on ...

Expanding a SAPUI5 class by incorporating a pre-determined header

In my attempt to expand a class using SAPUI5 methodology, I created a basic version to test its functionality. However, the predetermined title is not displaying in this particular example: var app; sap.m.Page.extend("MyPage", { title: "hi", rendere ...

Tips for Adding For Loop Value to an Array in JavaScript

Trying to Add For Loop Value to an Array My Current View <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script> <style> body { font-family: Roboto, sans-serif; } #chart { max-width: 650px; margin: 35px auto; ...

When I run my webpage, it appears blank even though vscode is not detecting any errors

Currently, I am working on a Youtube tutorial where I am building a social media website. However, I have encountered a problem with the front end code. Every time I try to npm start, my webpage fails to display correctly. You can find the front end code a ...

Unable to direct to the main page in index.js of the next.js application

I have been working on a next.js application and encountered an issue with a component I created called <ButtonGroup>. I added a button with the code <Button href="index">Home</Button> to allow users to navigate back to the home ...

Unlimited loading on middleware when implementing it within a post route

I have successfully implemented a middleware that checks if a user has submitted their data to a form already. If they have, it redirects them to an error page with a link to access their previous results if desired. Below is the middleware I created: modu ...

Showing scheduled activities according to their dates in FullCalendar

I'm facing an issue with my recurring weekly events showing up before the current week. How can I make sure that only events from the current week and beyond are displayed? The code I am currently using doesn't seem to work. Here is an example o ...

The DatePicker feature is functioning properly, however, the Autocomplete feature is not working

I have been working on developing an ASP.NET MVC Application, and surprisingly everything runs smoothly while testing it on localhost. However, once I publish the application, only the datepicker seems to work. I have inspected the folder where my Scripts ...

When utilizing styled-jsx alongside postcss, experiencing issues with styles failing to reload or rebuild

I'm currently using postcss in conjunction with styled-jsx. In my setup, I have multiple CSS files that I'm importing using the @import directive within the _app.js file. Everything seems to work smoothly, except when I modify any of the CSS file ...

Adding class name to alternate posts in Next.js

I am currently working on a project with nextjs where I am attempting to fetch a list of images. I want to dynamically add a class based on a condition. Specifically, for every even post, I want to add the class name "mt10". Below is the code snippet I am ...

Bug with IOS double tap on Element UI VueJS select input element

Encountering a strange problem on iOS safari or chrome. When attempting to select an option from a dropdown input, the options show up correctly on the first tap, but when trying to actually select an option, it requires two taps to work properly. This is ...

Using Jquery to assign a value to a checkbox

When I have 3 checkboxes arranged in a column, clicking on any checkbox should automatically set the value of all checkboxes in that entire column (not row). If a checkbox in the 2nd column is checked or unchecked, I want to ensure that all other checkbox ...

Having difficulties linking the front end and the back end despite diligently following the tutorial

Currently, I am experimenting with creating a real-time chat application by following a tutorial on YouTube from JavaScriptMastery. The tutorial link is here, and the GitHub repository is available at this link. Despite closely mimicking the code displayed ...