Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

275
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda