0

Possible Duplicate:
How to show the “Are you sure you want to navigate away from this page?” when changes committed?

I use a javascript message for confirming people who will exit the page, just if the for is not save, so I have the following code:

  <body onLoad="getdate2()" <?php if(!isset($_POST['enreg'])){ echo 
'onBeforeUnload="return(\'Vous n avez pas enregistr&eacute; les modifications 
apport&eacute;es. voulez vous vraiment quitter la page ?\')' ; } ?>">

The main trouble is that when The user click on the form submit button, this message appears.

Is there a way to just display that when the user click on the cross for exiting?

Community
  • 1
  • 1
Stanislas Piotrowski
  • 2,595
  • 10
  • 40
  • 59

1 Answers1

2

It looks like you're expecting PHP to affect how a page works in the browser. It doesn't work like that.

You need to remove the PHP and just leave the onBeforeUnload event. Then, in the onClick event of the Submit button, remove the onBeforeUnload event.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592