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

222
Visualizações
Turning onClick dispatchEvent into an Auto Click

I have a specific code that comes from Revolution Slider. Right now, if you click on this, it will popup like I need. But what I need it to do is auto popup once someone comes to the site. Essentially turning this into an auto click. How could I change this code in order to make it happen? You can see the code below.

You can also see the code working here: https://ae32d5d93a.nxcli.net/

<button id="clickMe" onclick="document.dispatchEvent(new Event('RS_OPENMODAL_slider-2')); return false">Auto Popup</button>

EDIT:

So I added it into a Magento 2 CMS Page and I am calling out the .js esstentionally. That part is working, as you can see the link grabs the javascript you sent me.

{{block class="Magento\Framework\View\Element\Template" template="Magento_Theme::popup.phtml"}}

https://ae32d5d93a.nxcli.net/static/version1645632931/frontend/Freshley/ultimo_child/en_US/js/popup.js

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

0

You can do a couple of things to achieve this.


  1. You add the onclick function in the body onload event. For example, something like this should work:
<body onload="document.dispatchEvent(new Event('RS_OPENMODAL_slider-2')); return false">
  1. You can use javascript and run this in the window.onload function. See below for an example:
window.onload = (event) => {
    document.dispatchEvent(new Event('RS_OPENMODAL_slider-2'));
    event.preventDefault();
};
  1. This is my least recommended one. You can have the button and then use javascript to click it automatically. See the code below to see how to do this:

    HTML:
<button id="clickMe" onclick="document.dispatchEvent(new Event('RS_OPENMODAL_slider-2')); return false">Auto Popup</button>


Javascript:

window.onload = () => {
    const button = document.getElementById('clickMe');
    button.click();
};

about 4 years ago · Juan Pablo Isaza Relatório

0

HTML

<button id="clickMe">Auto Popup</button>

CSS

to hide the button

#clickMe{
    position: absolute;
    top: 0;
    left: -9999px;
}

Javascript:

to run the code when the page loads

$(document).ready(function() {
    $.when($('#clickMe').click()).done(() => {
        document.dispatchEvent(new Event('RS_OPENMODAL_slider-2'));
    });
});

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