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

120
Visualizações
How can I freeze all DOM changes with JS?

How can I freeze all JS DOM changes completely using JS from a chrome extension?

Example: a user hovers over a button, which onMouseEnter displays a modal and hides it onMouseLeave. If I bind a callback to a certain keyboard-shortcut, how can I freeze the DOM in that point in time so that the modal stays visible and nothing can change in the DOM anymore (until the shortcut is pressed again) ?

I know there might not be a direct API to freeze the DOM, but I'm looking for any ideas that can help me do this.

One Idea I tried was:

  • When user presses the shortcut (toggles the freeze on)
    • grab the html node in current state
      • query and remove all script nodes
      • clone the html node (to get rid of bound listeners)
    • replace actual html node with the cleaned-out cloned html node (one without js scripts)
  • When user presses the shortcut again (toggles the freeze off)
    • replace the original DOM (with all script tags) back

However that didn't work, if I hovered my mouse over the button and the modal showed up, then I invoked that algorithm with the keybind, the cloning would happen successfully and script tags would be removed, however when I remove the mouse from the button the modal would just close. As if the button was still bound to onMouseLeave.

Edit: I'm trying to do this from an external script, specifically a chrome extension.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

if you have a function "myFunc" and want to malfunction it or disable it. you can clear the contents in window object.

<button onclick="freeze()">Freeze alert</button>
<button onclick="testAlert()">Test alert</button>
<script>
    function freeze() {
        window.testAlert = function testAlert() { };
    }

    function testAlert() {
        alert('The alert is active');
    }
</script>

The alert button will not work after clicking the freeze button.

about 4 years ago · Juan Pablo Isaza 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