Display popup when closing page [duplicate]

0

Hello. I would like to know a code to display a form as a popup when the user closes the page. That is, that moment when he takes the cursor over the browser. Because the page was made by the RD tool.

Form in question: link

Form Code:

<div id="formulario-071734d1611046a89c8d"></div>
<script type="text/javascript" src="https://d335luupugsy2.cloudfront.net/js/rdstation-forms/stable/rdstation-forms.min.js"></script><scripttype="text/javascript">
  new RDStationForms('formulario-071734d1611046a89c8d-html', 'UA-11653131074-1').createForm();
</script>

Thanks to anyone who can help.

    
asked by anonymous 24.02.2018 / 19:29

1 answer

1

You can use the mouseleave event on the document object.

This event is triggered every time a user leaves an area, in this case the area of the site.

new RDStationForms('formulario-071734d1611046a89c8d-html', 'UA-113131074-1').createForm();

document.onmouseleave = function() {
  console.log("oushe");
  document.querySelector("#overlay").style.setProperty("display", "flex", "important")
}
html, body {
  height: 100%;
  width: 100%;
}

#overlay {
  display: none !important;
  height: 100%;
  width: 100%;
  background:rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  position:absolute;
}
<script src="https://d335luupugsy2.cloudfront.net/js/rdstation-forms/stable/rdstation-forms.min.js"></script><divid="overlay">
  <div id="formulario-071734d1611046a89c8d"></div>
</div>

Insira o cursor aqui

You can also use the beforeunload event. It will be fired when the browser is about to close the entire page.

window.addEventListener("beforeunload", function (e) {
  var confirmationMessage = "Já vai sair?";

  e.returnValue = confirmationMessage;
  return confirmationMessage;
});
  

The error that appears is a problem in external JavaScript.

    
24.02.2018 / 19:46