Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

72
Vistas
How to execute code only after the submission is done?
  1. I have some code from a service called webflow where the form is controlled by them. I write the html form, but the form submission code is handled by a third party not me
  2. I need to run some code (trigger a redirect) after their submission is done.

Here is my attempt

$('#email-form').submit(function (event) {      
    window.location.href = url;
});

It works in some browser, but not in safari. Apparently, this breaks this original form submission code.

My second attempt, this works

    $('#email-form').submit(function (event) {      
    setTimeout(function(){
    window.location.href = url;
    }, 500);

});

By giving it some time, the submission code fires first, then my code runs and successfully redirects.

What is a more robust way of writing this code (not reliant on some random timer wait)?

7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think the best way to work this in every browser is 👇

setTimeout(function(){document.location.href = "your link";},250);
7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos