Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

119
Vistas
I am trying to close the window after executing some code but the window is not closing, tried window.close(); and close(); still not working

//close window section is the problem, it just won't close the current tab. I am jus running some code to download a file and then I require the tab to close automatically as if nothing happened to make the UX better. But window.close(); and close(); is not working. Tried a lot of stuff found on Internet still not working. What's wrong with my code?

var url_string = window.location; //window.location.href
var url = new URL(url_string);
var file = url.searchParams.get("file");
var dFile = file;

function onLoad() {
  if (dFile !== null) {
    var hiddenElement = document.createElement('a');

    // Download
    hiddenElement.href = `${dFile}`;
    hiddenElement.target = '_blank';
    hiddenElement.download = `${dFile}`;
    hiddenElement.click();

    //Close Window
    var win = window.open("about:blank", "_self");
    win.close();
  } else {

  }
}

//Set The value of the File being Downloaded
if (dFile !== null) {
  var SetFile = document.getElementById('xdFile')
  SetFile.innerHTML = "Downloading" + " " + dFile + " " + "now"
}

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda