We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

before leaving form incomplete js Plugin somebody | Forum

Topic location: Forum home » Support » General Questions
Ken
Ken Apr 24 '20
Somebody build this plugin for oxwall already and it should be free <br />
I have some pages with forms in my application.<br />
<br />
How can I secure the form in such a way that if someone navigates away or closes the browser tab, they should be prompted to to confirm they really want to leave the form with unsaved data?
The Forum post is edited by Ken Apr 24 '20
Patricia Zorrilla Leader
Patricia Zorrilla Apr 24 '20

<script language="JavaScript">

  window.onbeforeunload = confirmExit;

  function confirmExit()

  {

    return "Ha intentado salir de esta pagina. Si ha realizado algun cambio en los campos sin hacer clic en el boton Guardar, los cambios se perderan. Seguro que desea salir de esta pagina? ";

  }

</script>

Ken
Ken Apr 24 '20
That script doesn’t work for me
Patricia Zorrilla Leader
Patricia Zorrilla Apr 24 '20

It works perfectly




dave Leader
dave Apr 26 '20

"Sometimes" script tags need to be wrapped in a literal tag


<literal>

<script type="text/javascript">

whatever code

</script>

</literal>



type= is also no longer require nor is language = but i like using the type, old habbit..



Patricia Zorrilla Leader
Patricia Zorrilla Apr 26 '20

I did a quick test for him at https://codepen.io/ , I didn't even put in a text in English.

When he answered that it didn't work for him I did a quick test on any OxWall HTML and it worked too.

It wasn't a programming example, I just wanted to bring up the idea of using the event window.onbeforeunload from JavaScript.

You're right, Dave! :)