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

274
Vistas
How can I close the last opened popup in order?

How can I close the last opened popup in order?

The image below is an image where popup tags are stacked down whenever a popup is opened.
enter image description here

Below is the applied source.

/* ESC popup close start */
$(document).on('keyup', function(e) {
  if (e.key == "Escape") $('.window .close').last().click();
});
/* ESC popup close end */
about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

  • Be sure that the close click event before the click trigger
  • You need to addClass to the last .window element to avoid it when you order the last item again

$(".close").on("click" , function(){
  $(this).closest(".window").hide();
});


/* ESC popup close start */
$(document).on('keyup', function(e) {
  if (e.key == "Escape") $('.window:not(.hidden)').last().addClass("hidden").find(".close").click();
});
/* ESC popup close end */
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="window">Window 1<div class="close">X</div></div>
<div class="window">Window 2<div class="close">X</div></div>
<div class="window">Window 3<div class="close">X</div></div>

about 4 years ago · Santiago Trujillo Denunciar

0

Simply set popup window to any variable and close using that variable using window.close

const daddyWindow = window.open("", "window" + number, "width=200,height=100");
daddyWindow.document.write('window Popup code');
daddyWindow.close();

Try this:

<html>
<header>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
        let openedWindows = [];
        let newWindow;
        let number = 0;
        function openWindow() {
            number++;
            newWindow = window.open("", "window" + number, "width=200,height=100");
            newWindow.document.write(`<a href="javascript:window.close();"class="video-close">Close this window ${number}</a>`);
            openedWindows.push(newWindow);
        }

        $(document).on('keyup', function (e) {
            if (e.key == "Escape") {
                if (openedWindows && openedWindows.length >= 0 && openedWindows[openedWindows.length - 1]) {
                    openedWindows[openedWindows.length - 1].close();
                    openedWindows.pop()
                }
            }
        });
    </script>
</header>

<body>
    <h3 style="color:brown"> Close Window Example </h3>
    <button onclick="openWindow()">Open New Window</button>
</body>

</html>
about 4 years ago · Santiago Trujillo Denunciar
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