Functioning properly on Firefox, Bootstrap modal encounters issues on Chrome

The following code snippet demonstrates closing one modal, opening another, and executing a parsing function upon button click:

$('#BtnUpCsv').on('click', function (e) {
      $('#csvModal').modal('hide');
      $('#pBarModal').modal('show');
      Papa.parse(document.getElementById('csvinput').files[0], {...

While this code functions correctly in Firefox, it exhibits unexpected behavior in Chrome where the first modal fails to close immediately after the function is triggered. Instead, the parsing function seems to take precedence over the modal operations. The 'csvModal' eventually closes and the 'pBarModal' surfaces once the parse completes.

I attempted implementing a setTimeout, but it interfered with the parsing process. Any insights on why this anomaly occurs?

UPDATE: complete code snippet below

Papa.parse(document.getElementById('csvinput').files[0], {
        // Various parsing configurations
        complete: function(results) {
          // Parsing results handling and data processing logic
        }
      } );
    } );

Answer №1

Aha! I have now grasped the essence of your issue. To illuminate the problem and its solution, I have fashioned a JSFiddle for you to peruse: take a look here

The reason why it appears that your parsing function is overshadowing the modal's display control is due to the asynchronous nature of the modal functions. Essentially, this implies that the modification to the HTML (showing or hiding modals) does not begin until all the code has executed. It patiently waits for the parsing function to conclude before executing the modal display/hide commands.

To rectify this, you must ensure that the modal is fully displayed prior to triggering the parsing function. The specific section in the fiddle where this adjustment occurs is as follows:

$("#testbtnSolution").click(function() {
    $("#exampleModal").modal('hide');   
    $("#exampleModal2").one('shown.bs.modal', function() {
      longExecutingFunction(2000);
      alert("processing done");
    }).modal('show');  
});

In this snippet, we set up an event listener that triggers upon shown.bs.modal. Once the modal finishes its presentation, only then will your processing function be invoked.

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

What is the best approach to display a fluctuating price depending on specific options chosen in Next.js?

When working with 2 different select tags and rendering images based on the selection, I also want to display a price determined by the options chosen. For instance, selecting "Your Current Division" as Iron and "Your Desire League" as Bronze/Silver/Gold s ...

During the installation process of Next JS, I faced a challenge that hindered

While setting up NextJS, I ran into the following issue: D:\Codes\React\Learn>npx create-next-app npm WARN using --force Recommended protections disabled. npm WARN using --force Recommended protections disabled. npm ERR! code E404 npm ERR ...

Developing a progress bar with jQuery and Cascading Style Sheets (

Below is the code I'm currently using: <progress id="amount" value="0" max="100"></progress> Here is the JavaScript snippet I have implemented: <script> for (var i = 0; i < 240; i++) { setTimeout(function () { // this repre ...

Styled-Elements Text or Passages

Can we apply styling to text or paragraphs with styled-components? And if so, how can we insert text into the component? For instance, consider this Footer component: const Footer = () => ( <footer className="site-footer"> <p className= ...

In Firefox, using the new Date function within a string does not function as expected

Why does the last log in the code snippet below not work in Firefox? (function() { String.prototype.toDate = function() { return new Date(this); }; console.log(Date.parse("2012-01-31")); console.log(new Date("2012-01-31")); c ...

Unable to set an onclick function within a customized dojo widget

I have a custom widget that I've defined as shown below: dojo.declare('myWidget', [dijit._WidgetBase, dijit._Templated], { 'templateString':'<span>' + '<a dojoAttachPoint="linkNode" href="b ...

What strategies can I employ to address this historical issue?

Encountered TypeError: (0 , history_history__WEBPACK_IMPORTED_MODULE_6_.default) is not a function This issue arises in my history.js file import { createBrowserHistory } from 'history'; export default createBrowserHistory({ forceRefresh: tr ...

Exploring hierarchical information within a JSON response from a Wiki API

As a newcomer to this field, I am currently exploring ways to access Wikipedia's API for extracting the value of "extract" and adding it to an HTML element dynamically. The challenge lies in the fact that the information is subject to change based on ...

Concealing the nearest object

I am currently working on using jquery to hide certain content on a website's index page. Within the fiddle, there is commented out code which I have been experimenting with - however, it hides all content divs if any toggle link is clicked. HTML & ...

Utilizing NodeJS and Express to efficiently share sessions across various routes

I have a Node.js web application built with Express that has multiple routes. These routes need to be able to access and share the session data when interacting with users. The routes are separated into different js files from the main app file, app.js. I ...

Guide to embed a Google Sheets chart into a WordPress website

I'm looking to include a chart in a wordpress post, using the script generated from google sheets' publish function. When I add the script to a generic HTML page, the chart displays properly. However, when I insert it into a wordpress post, I en ...

Console output shows that the function results in undefined

When I pass a string parameter to a function, I expect the console to display "reff", but it is showing "undefined" instead. Here is the code snippet: var _ref; function foo(_ref='reff') { var bar = _ref.bar; return console.log(bar); } foo ...

Retrieve Cookie from a designated domain using Express

I am currently working on a React application that communicates with a Node/Express backend. To ensure the validity of requests, I am sending a cookie created by react-cookie from the React app to the Express app. To avoid issues related to naming conflict ...

Unusual scroll bar movements when using jQuery validation

When I click the Add Dependent link button, I wanted the scroll bar to automatically scroll to the bottom, and it does just that. However, there is a small issue after the postback where the text "Please fix the following problems:" briefly appears, even t ...

AngularJS modal not functioning properly after sending $http request

I have successfully implemented a pop-up modal in my Angular page using code from a reliable source. However, when I include a button for an HTTP request on the same page, the functionality of the AngularJS modal stops working after the HTTP request is mad ...

Error message: A circular structure is being converted to JSON in Node.js, resulting in

So here is the error message in full TypeError: Converting circular structure to JSON --> starting at object with constructor 'Socket' | property 'parser' -> object with constructor 'HTTPParser' --- prope ...

The issue of the background image not updating with jQuery persists in Internet Explorer 11

Hello everyone, I am facing an issue where I am trying to change the background image of a div using jQuery on click. The code I have written works perfectly on all browsers except for IE. Can someone please provide me with some guidance or help on how to ...

Highcharts - problem with chart width being fully rendered

I am currently using a Highcharts column chart and I am looking to make it a fully responsive chart with 100% width. The container for the chart is a simple <div> without any additional formatting. Upon document load, the chart remains at a fixed wid ...

When working with async functions in JavaScript using await, the second function may not necessarily wait for the first function to complete before executing again

My goal is to implement async await in Angular 10 for loading a list of users from the backend database (built with Spring Boot and MariaDB) using an http request, and then filtering that list for one specific user. However, I'm facing an issue where ...

Retrieving data from a Bootstrap range slider

Trying to retrieve a variable from a price range slider for my online store. I aim to display the value using PHP. Here is the snippet from my test.php file: <script> var slidervalue = $('#output').val(); </script> <?php ...